I am trying to make a query that does the following... If I have a table full of rows that have article_ids that look like... 1 - article_id = 1 2 - article_id = 3 3 - article_id = 3 4 - article_id = 9 5 - article_id = 1 6 - article_id = 3 So basically I want to retrieve the distinct rows, so grabbing them in a fashion where I get a single row for article_id 1, 3 and 9 - More so, I would like to order them by which one shows up, so 3 would come up first, then 1 and finally 9. Last but not least, I would like to limit it to something like 1 or 2 rows. What kind of query do I need to accomplish this?
Are you looking for this? SELECT article_id, COUNT(*) appearances FROM table GROUP BY article_id ORDER BY appearances ASC LIMIT 2 Code (markup):