My SQL. Finding multiples in a single column

Go To StackoverFlow.com

1

Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram, hd) Printer(model,price, color, price)

I am trying to find pc's who share HD sizes with one another. So basically finding out the model number of pc's who share a HD size with another pc.

What I have tried:

SELECT DISTINCT hd FROM pc; 

Which gives me all of the HD sizes. I am not sure how I would go about figuring out if those numbers occur twice in a relation.

I figure it is something along the lines of

SELECT DISTINCT hd FROM pc WHERE hd IN (SELECT hd FROM pc);

But I am not sure how to say " IN MULTIPLE TIMES" ?

2012-04-03 22:26
by NoName


1

You can use the GROUP BY and HAVING clauses to accomplish this:

SELECT hd, COUNT(*) AS occurrences
FROM pc
GROUP BY hd
HAVING COUNT(*) > 1
2012-04-03 22:28
by Michael Fredrickson
Ads