Let's say I have this table:
+----+------+---------+
| Id | Item | Country |
+----+------+---------+
| 1 | b123 | Austria |
| 2 | a123 | Italy |
| 3 | b990 | Germany |
| 4 | h231 | Austria |
| 5 | y233 | France |
| 6 | u223 | Austria |
| 7 | p022 | Spain |
| 8 | d133 | Italy |
| 9 | w112 | Germany |
| 10 | j991 | Austria |
+----+------+---------+
I want to do SELECTin this table and order the results with which I Countryrepeat the most. Thus, the expected result should be:
+----+------+---------+
| Id | Item | Country |
+----+------+---------+
| 1 | b123 | Austria |
| 4 | h231 | Austria |
| 6 | u223 | Austria |
| 10 | j991 | Austria |
| 2 | a123 | Italy |
| 8 | d133 | Italy |
| 3 | b990 | Germany |
| 9 | w112 | Germany |
| 5 | y233 | France |
| 7 | p022 | Spain |
+----+------+---------+
How can i do this?
I tried this:
SELECT * FROM items WHERE Item != '' GROUP BY Item HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC
But this will return something like this:
+----+------+---------+
| Id | Item | Country |
+----+------+---------+
| 1 | b123 | Austria |
| 8 | d133 | Italy |
| 3 | b990 | Germany |
| 5 | y233 | France |
| 7 | p022 | Spain |
+----+------+---------+
source
share