beginners SQL question

  • Thread starter Thread starter rich
  • Start date Start date
R

rich

Hi,

I have a table with 2 columns ID,Name,

I would like to write an SQL statement to list all the different names
(no duplicates) the end result would be the name with its ID.
e.g If Name Rich was in the table 10 times. Rich would only appear once
in the list and with the highest ID number.

Any ideas? thanks in advance.

Rich
 
SELECT Max(Table2.ID) AS MaxOfID, Table2.Name
FROM Table2
GROUP BY Table2.Name;

Change 'Table2' to the name of your table.

BTW: 'Name' is a reserved word and can cause problems when used as a field
name.
 
You could do a group by query on Names and specify MAX instead of group by
for the ID
 
Back
Top