Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering for UNIQUE records in one table 2

Status
Not open for further replies.

shilpashetty27

Technical User
Apr 12, 2007
32
CA
Hi all,

I've been trying to accomplish the filtering out of duplicate data in the following table.

ID Name Code
1 x Pink
2 y Red
3 z Orange
4 z Orange

From the table above, I'm trying to filter out duplicate 'Name' fields and obtain only unique 'Name' fields with corresponding 'Code' fields.

Therefore, i'd like the results of my query to look like this:

ID Name Code
1 x Pink
2 y Red
3 z Orange


Any help on this is appreciated.
Tks in advance,
Cheers,
Shilpa
 
SELECT Min(ID) AS MinID, Name, Code
FROM yourTable
GROUP BY Name, Code

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV for your reply. I did try out your suggestion but unfortunately it doesn't seem to be filtering out the duplicates in the 'Name' column.

Any more ideas perhaps???


Thanks again!
Shilpa
 
What are your actual SQL code, actual result and expected result ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What about a DISTINCT?

SELECT DISTINCT Name, Id, Code
FROM yourTable
 
Thanks PHV and Karja,

I checked PHV's method again and it just so happened that I had overlooked something.
Both your suggestions worked perfectly fine for me!

cheers,
Shilpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top