T-SQL How To Select Rows Without Duplicate Values From One Column?
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 2
Solution 1:
You need to GROUP BY:
SELECT MAX(ID) as [ID], ID_PROJ_CSR
FROM my_table
GROUP BY ID_PROJ_CSR
Solution 2:
Here's the case of omitting anything that has a duplicate value, so you'll only get rows that don't have duplicates:
SELECT *
FROM my_table
GROUP BY ID_PROJ_CSR
HAVING count(ID_PROJ_CSR) = 1;
Post a Comment for "T-SQL How To Select Rows Without Duplicate Values From One Column?"