Pages

Wednesday, May 23, 2012

How to SELECT NON DISTINCT COLUMNS FROM A TABLE.


SELECT [COLUMN]
FROM [TABLE] T1
WHERE (SELECT COUNT(*) FROM [TABLE2] T2 WHERE T1.[COLUMN] = T2.[COLUMN]) > 1

This returns all of the non distinct (opposite of distinct) rows.


SELECT [COLUMN], Count(*)
FROM [TABLE]
GROUP BY [COLUMN]
HAVING COUNT(*) > 1

This returns what is distinct and how many rows there are that has the value.

No comments:

Post a Comment