sql server - Distinct on one column -


i have through duplicated question solution there not work me.

i have 2 columns:

instanceid  productid 

and want unique productids only.

from others questions asked here try solution:

select *      (select cast(a.col001 int) surveyinstanceid ,             cast(a.col002 nvarchar(25)) productid ,             row_number() over(partition a.col002 order a.col001  desc) rn     datasetsmaterializeddatasqlvariant      datasetsmaterializedinternalrowsetid = 5     ) rn = 1 

but result duplicated values.

edit:

for more information, have in table:

instanceid  productid   1           10  1           11  1           12  1           13  2           10  2           a1  3           10  3           11    3           b1    3           c1    3           d1  3           e1 ...... 

i need unique product ids. sorry did not provided example @ beg.

that seems way complex. try this:

select distinct productid datasetsmaterializeddatasqlvariant  datasetsmaterializedinternalrowsetid = 5  

or if want both columns need specify instanceid select if there more one:

select productid, max(instanceid) datasetsmaterializeddatasqlvariant  datasetsmaterializedinternalrowsetid = 5  group productid 

if not looking please post sample data , desired output.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -