Reputation: 976
I have this two tables :
categorie :
and another table named "thynk" :
each line in table thynk is linked with a categorie.
Anyway i would like to know if it's possible to select categorie_id which contains most of thynk ? (with postgresql)
So here i should have this result :
categorie_id
--------------
0
5
3
Upvotes: 3
Views: 57
Reputation: 311823
You could group by categoire_id
, count the results in each group and order accordingly:
SELECT categorie_id, COUNT(*)
FROM thynk
GROUP BY categorie_id
ORDER BY 2 DESC
Upvotes: 1