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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique records

Status
Not open for further replies.

nuVBer

Programmer
Jul 6, 2001
63
US
I have a view that returns data that looks like this:

ID Comp_Sk
1 101
2 102
2 103
3 105

I want to return only the first, third and fourth rows. The duplicate record that has 102 as the Comp_Sk value of 102 should be eliminated from the select. I just want the largest value of the Comp_Sk field. What's the best way to do this?
 
Try this:

select id, max(comp_sk)
from view_name
group by id
order by id asc


-SQLBill
 
Dear ;


Create table Test1
(PrimaryID [int] ,
Data [int]
)

insert into test1 (Primaryid , data) values (1, 100)
insert into test1 (Primaryid , data) values (2, 102)
insert into test1 (Primaryid , data) values (2, 103)
insert into test1 (Primaryid , data) values (3, 104)


Select PrimaryID , max(Data) from test1
Group by PrimaryID

Regards ,
Muhammad Essa Mughal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top