Reputation:
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" ?
Upvotes: 1
Views: 74
Reputation: 37398
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
Upvotes: 1