O
orekinbck
Hi There
Our test database has duplicate data:
COMPANYID COMPANYNAME
1 Grupple Group
2 Grupple Group
5 Grupple Group
3 Yada Inc
4 Yada Inc
6 Bodgy Brothers
I want to get a list of distinct company names and the most recent ID
for each distinct company name - For example, the query should return:
5 Grupple Group
4 Yada Inc
6 Bodgy Brothers
I tried
SELECT DISTINCT COMPANYNAME, ID FROM MYTABLE ORDER BY COMPANYNAME
But the above query does not work as I expect.
How do I form an SQL query that gets back the DataSet I am after? I
would prefer not to use stored procedures.
TIA
Bill
Our test database has duplicate data:
COMPANYID COMPANYNAME
1 Grupple Group
2 Grupple Group
5 Grupple Group
3 Yada Inc
4 Yada Inc
6 Bodgy Brothers
I want to get a list of distinct company names and the most recent ID
for each distinct company name - For example, the query should return:
5 Grupple Group
4 Yada Inc
6 Bodgy Brothers
I tried
SELECT DISTINCT COMPANYNAME, ID FROM MYTABLE ORDER BY COMPANYNAME
But the above query does not work as I expect.
How do I form an SQL query that gets back the DataSet I am after? I
would prefer not to use stored procedures.
TIA
Bill