I have next sql
select site_id,count from tags where match (tag) against ('statistici' in boolean mode) ORDER BY count DESC;
+---------+-------+
| site_id | count |
+---------+-------+
| 9 | 1300 |
| 13 | 1200 |
| 9 | 1100 |
| 13 | 1000 |
| 9 | 900 |
| 13 | 800 |
| 13 | 800 |
+---------+-------+
What i need is to get distinct site_id.
But when i use a group by statement the order by count is not kept
select site_id,count from tags where match (tag) against ('statistici' in boolean mode) GROUP by site_id ORDER BY count DESC;
+---------+-------+
| site_id | count |
+---------+-------+
| 13 | 1000 |
| 9 | 900 |
+---------+-------+
What should i do ?
You’re ordering by
ORDER BY count DESC, and the result is ordered with the highest count first.Change to
ORDER BY count ACSif you prefer the lowest count first.EDIT: Based on your comment, perhaps this is more like what you’re trying to achieve:
This selects the highest count per site, and places the highest count first.