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" ?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.