tags:

views:

17

answers:

1

Hi, I have a table with 2 columns:

ID, ID_PROJ_CSR

the content of that table is:

ID ID_PROJ_CSR

747 222

785 102

786 222

787 223

788 224

I want to select the ID, but if any value from ID_PROJ_CSR is a duplicate, I need to select any ID of the rows that contains that duplicate value (in that example, select ID 747 OR 786

I try:

select * from my_table tab 
where tab.id_proj_csr =(select top 1 id_proj_csr
                        from my_table mt
                        where mt.id_proj_csr = tab.id_proj_csr)
+3  A: 

You need to GROUP BY:

SELECT MAX(ID) as [ID], ID_PROJ_CSR
FROM my_table
GROUP BY ID_PROJ_CSR
ck
+1 Nice and simple. Think its also worth mentioning that you got around the duplicate IDs, by using MAX.
kevchadders