Counter of Festivals

Ashok Blog for SQL Learners and Beginners and Experts

Wednesday, 5 June 2013

Query to display Unique id with any one of Productid:



Unique Versionid with any one of Productid:
If your table have same versioned with different product. But you want to display unique versioned with any one of the productid means see below:
The below data Same versionid with different Productid.

 

If we want Unique Versionid with any one of the productid means
select distinct versionid,max(productid) as productid from supportKBVersions_ToProduct group by versionid

Output:

 

(Or)

with a
as
(
select distinct ROW_NUMBER()over(partition by productid
order by versionid,productid)as [Dup],*
from supportKBVersions_ToProduct
)
select distinct versionid,max(productid)as [Productid]
 from a
group by a.versionid
order by a.versionid