Reputation: 1678
I have a two columns in a table say columnA and columnB. I want to select duplicate entries for columnA where columnB=xx or columnB=yy. For Example
columnA columnB
12 abc
12 pqr
11 abc
10 pqr
9 xyz
for above table I want to get 12 as a result. which is common for columnB=abc or columnB=pqr.
Please help me to build a sql query. I tried with count(*) but coudn't get the result.
Upvotes: 3
Views: 82
Reputation: 15048
SELECT a.columnA
FROM MyTable a
INNER JOIN MyTable b ON a.columnA = b.columnA
WHERE a.columnB = 'abc'
AND b.columnB = 'pqr';
Upvotes: 2
Reputation: 3643
SELECT columnA, count(columnA)
FROM tableName
GROUP BY columnA
HAVING count(columnA)>1
this will at least give you a list of all duplicated entries, followed by the count of dupes.
Upvotes: 0