OK when I make a request I want all the items with the same group_id to be “together” for example 117,117,134,111 is fine but 117,134,117,111 is not fine because the group_id 117 are not all “together”. I hope that makes sense. The only way I know how to do achieve this is by ordering my results by group_id, but if I want to order by like price or something is there a way to do that while keeping all the matching group_id’s together?
Thanks.
Yes, you just order by both, so your
ORDER BYshould look like this:That will first order by group_id, then by price. So all the same group_ids will be together, but whenever there are multiple with the same group_id, they will be ordered by price.
Your question is a little ambiguous though, so just to explain in case it’s what you actually wanted – there’s no easy way to “mainly” order by price and just keep identical group_ids together, that doesn’t really make any sense. What I mean is, if you had the following data:
You can’t easily select it in this order: