tags:

views:

58

answers:

3

I have a table called Laptop that has a column named "HD". How can I write a query that will find all "HD" entries that occur twice or more?

[HD]
10
20
20
40
50
10

So, out of those entries in HD, the query will return 10, and 20 because they both occur twice or more.

+2  A: 

This is surely a duplicate, but couldn't find it. Anyhow, you do it with the HAVING clause after an aggregate.

SELECT HD,COUNT(HD) FROM Laptop GROUP BY HD HAVING COUNT(HD) > 1
Vinko Vrsalovic
A: 

select HD from LapTop group by HD having count(*)>1

Bjorn
+1  A: 

SELECT HD, count(HD) FROM LAPTOP GROUP BY HD HAVING COUNT(HD) > 1

James Anderson
Why did you add the exact same answer (except the capitalization change in LAPTOP and count) 4 minutes later?
Vinko Vrsalovic
Sychroicity! There were no answers when I started typing, and, I delayed a little while I fired up sqlserver to check the "Having" sysntax was correct. It is after all THE correct answer so its not surprising two or more people came up with it.
James Anderson