954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Select distinct question

Hi guys,

I'm wondering if there is a way to solve this problem. Currently, I have an SQL statement that goes this way:

SELECT distinct name,id from list

My understanding is that it selects the things that are distinct on both tables.
Example:
id name
1 Joe
2 Joe


It will return to me the two rows because although the name is the same, the ids are not. Is there an SQL statement that will allow me to select a distinct name and still grab the id field? Basically I want to

SELECT distinct name from list


but grab the id too. In the previous example, it should just return 1 name with either of the ids.

martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
 

I think this should do it:

SELECT name, id FROM list GROUP BY name ORDER BY name, id
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Thanks a lot. That did the trick!

martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: