MYSQL query filter out duplicates
MPG Radio last edited by
The below query produces results
$sql = "SELECT date_and_time, title, stream, listeners FROM song_stats WHERE listeners BETWEEN 5 AND 9 ORDER BY listeners DESC";
How could I modify this query to only show one instance not show multiple of the same?
The requirement would be anything that matches "title and stream" only show the entry once.
avan last edited by
Here is something I found online (https://stackoverflow.com/questions/11937206/sql-query-multiple-columns-using-distinct-on-one-column-only)
select * from tblFruit where tblFruit_ID in (Select max(tblFruit_ID) FROM tblFruit group by tblFruit_FruitType)
So in your case it would be something like
select * from song_stats where date_and_time in (Select max(date_and_time) FROM song_stats group by title) AND listeners BETWEEN 5 AND 9
But I don't know SQL so I don't know if this is going to work. It might be off by one field or so.