2

The title seems to do a really poor job at describing my problem; let me try and explain it with a simplified example:

lets say I have the following table:

_______________________
|id|variant_id|attr_id|
|__|__________|_______|
|1 |15        |110    |
|2 |15        |110    |
|3 |20        |152    |
|4 |20        |110    |
|5 |21        |110    |
|__|__________|_______|

Now, what I'd like to have is a query that selects all rows where a combination of the variant_id and attr_id columns occurs more than once. Basically in this example it should select row 1 and 2, because their combination of variant_id and attr_id occurs more than once in the table.

Is that possible? My head hurts from trying to think of a possible solution.

2 Answers 2

6

Try this query

SELECT a.* FROM 
tbl a 
inner join 
tbl b
ON a.variant_id =b.variant_id AND a.attr_id = b.attr_id
WHERE a.id <> b.id;

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

AH of cause! I forgot you could join tables on themselves! Thanks this work flawlessly.
5
SELECT variant_id, attr_id
FROM YouTable
GROUP BY variant_id, attr_id
HAVING COUNT(*) > 1

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.