tags:

views:

150

answers:

5

Hi all,

How could I filter out the duplicate value in a column with SQL syntax?

Thanks.

A: 

distinct would be the keyword to filter douplicates. May be you can explain a little more what you're trying to achieve ?

Nils
Sorry for the ambiguous question. My "real intent" is to select the rows where the criteria depends on the "duplicate values" of a column.
Ricky
+2  A: 

Depending on how you mean "filter" you could either use DISTINCT or maybe GROUP BY both are used to Remove or Group duplicate entries.

Check the links for more information.

A snippet from the DISTINCT-link above:

SELECT DISTINCT od.productid
FROM [order details] OD

SELECT od.productid
FROM [order details] OD
GROUP BY od.productid

Both of these generally result in the same output.

Filip Ekberg
+2  A: 

Use DISTINCT or GROUP BY** clause.

Select DISTINCT City from TableName

OR

Select City from TableName GROUP BY City
adatapost
+1  A: 

A common question, though filtering out suggests you want to ignore the duplicate ones? If so, listing unique values:

SELECT col 
FROM table
GROUP BY col 
HAVING (COUNT(col) =1 )

If you just want to filter so you are left with the duplicates

SELECT col, COUNT(col) AS dup_count
FROM table
GROUP BY col
HAVING (COUNT(col) > 1)

Using http://www.mximize.com/how-to-find-duplicate-values-in-a-table- as a base.

Mead
The ref help a lots. Thanks.
Ricky
A: 
anishmarokey
Seriously? You couldn't have demonstrated that in another way than screenshots? :)
Filip Ekberg