Hello,
I have a simple mySQL table with the following columns: id and artist_id
The ID column is the primary key. Is there anyway I can select all of the artist_id columns, but not have any of them repeat?
Hope that makes sense![]()
Thanks!![]()
| SitePoint Sponsor |
Hello,
I have a simple mySQL table with the following columns: id and artist_id
The ID column is the primary key. Is there anyway I can select all of the artist_id columns, but not have any of them repeat?
Hope that makes sense![]()
Thanks!![]()
Patrick Lucas
SELECT DISTINCT artist_id FROM your_tablename;
Ah. Hoped it'd be simple. Thanks!![]()
Patrick Lucas
Now... Is there any easy way to order the results by occurrence?![]()
Patrick Lucas
you mean count each artist_id and sort them from most to least? this will do that:
Code:SELECT COUNT(*) AS count, artist_id FROM table GROUP BY artist_id ORDER BY count DESC
- Matt
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
Bookmarks