'Add constraint to allow only distinct duplicates
I'm not sure if this has been asked before but I can't seem to find it anywhere.
I want to add a constraint to allow only distinct duplicates of two columns:
User Fob
2 123
2 123
2 456 <<<< NOT ALLOWED
So the last row is not allowed because it's a new combination of distinct values between Users and Fobs.
Solution 1:[1]
You can count each combination and get only those having more than 1.
SELECT
User,
Fob,
count(*) as lines
FROM example_table
GROUP BY User, Fob
HAVING COUNT(*) > 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rodrigo Cava |
