I have a database full of media. For simplicity sake, lets say it has
Table: media
id
college_id
title
shares
I’m trying to get the articles with the most amount of shares from each college. So, in essence, get the top shared article from Cornell, USC, Syracuse.
I have been using this SQL command, but it doesn’t return the most shared article from each college.
SELECT *
FROM media
GROUP BY college_id
ORDER BY shares DESC
Anyone have any ideas?
The shares column is an integer indicating the number of shares.
That was my first thought… though I’m wondering if I’m missing something since this answer is a lot simpler than Adam’s. If shares is the number of times it’s been shared though this sound like what you’re looking for.
Edit: I see now. Here’s another way…
This will return more than one article per college in cases where there is a tie. I don’t if you want that or not.