I have table in the following structure, I need to write SQL to find the product having multiple product keys? Can anyone please help to write the SQL?
Product | Product Key |
---|---|
First | 10 |
First | 1 |
Second | 2 |
Second | 2 |
Third | 3 |
Four | 3 |
Test | 5 |
Test | 5 |
Expected output would be
Product |
---|
First |
Third |
Four |
This is how you get using syntax from SQL Server
SELECT Product
FROM Products
WHERE "Product Key" IN (
SELECT "Product Key"
FROM Products
GROUP BY "Product Key"
HAVING COUNT(DISTINCT Product) > 1
)
GROUP BY Product;
These are the steps:
product key
that contain multiple product.1
and 3
.1
and 3
.This is fiddle for sql server.
You can adjust it to monetdb syntax