MySQL Forums
Forum List  »  PHP

Re: array two of a kind
Posted by: Rick James
Date: July 11, 2015 12:16PM

That is essentially "groupwise max" where you want 2 rows per user_id and (perhaps) don't care which 2.
http://mysql.rjweb.org/doc.php/groupwise_max -- see the two "Top-N" sections in that blog.
Change
* `province` to `user_id`
* `Canada` to your tablename
* 3 to 2 (You want 2 each)
* `population` to `id` -- I'll have it get the 2 with the smallest `id`
* DESC to ASC -- to get the smallest `id`s, not largest
* SELECT id, user_id, name

Options: ReplyQuote


Subject
Written By
Posted
July 09, 2015 10:02AM
July 10, 2015 04:25PM
July 10, 2015 08:25PM
July 11, 2015 08:29AM
Re: array two of a kind
July 11, 2015 12:16PM
July 11, 2015 01:19PM
July 11, 2015 01:53PM
July 11, 2015 01:58PM
July 12, 2015 04:24PM
July 12, 2015 08:04AM
July 13, 2015 06:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.