Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Easy Query Question-

Author  Topic 

postmaster.chris
Starting Member

3 Posts

Posted - 2006-05-11 : 12:13:52
I have a table with these fields:

Products_ID, ID_num, Description, Price
with data like this:
1, 112A, Item1, 3.33
2, 112A, Item2, 23.32
3, 382B, Item3, 392.3
5, 382A, Item4, 3.23
6, 382B, Item5, 2.38

And I need the Query to produce these results:
1, 112A, Item1, 3.33
3, 382B, Item3, 392.3
5, 382A, Item4, 3.23

The Query should return only distinct ID_num's. It should get all the ID_num's in the table, but if there are duplicate ID_num's it should only return the 1st one found, along with the other table data for the row.

I'm stumped!

Any help appreciated!

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-11 : 12:16:01
select *
from tbl t
where t.Products_ID in (select min(Products_ID) from tbl group by ID_num)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

postmaster.chris
Starting Member

3 Posts

Posted - 2006-05-11 : 12:31:19
I spent 4 hours on this problem. And you replied in 3 minutes!!!

Thank you sooooo much!
Go to Top of Page
   

- Advertisement -