This should be very simple, but I cannot find the correct syntax using search.
I have:
SELECT distinct name, id FROM table1 WHERE length<6;
I want to return the id’s and names of all distinct names (not distinct ids, since thats an auto increment anyway), but this query is currently returning all names and ids, not just the distinct names…
What’s the correct way to do this?
Edit: Length is another columns name and not relevant specifically here.
So it sounds like you want distinct names, and any associated id.
DISTINCTwill return distinct rows as combinations of the selected columns, and sinceidis auto-increment, that means all rows. Instead use an aggregate.This query will return the name, and the first auto-increment
idwith it: