3

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.

Linger
  • 14,942
  • 23
  • 52
  • 79
Kalpesh Patel
  • 1,638
  • 1
  • 20
  • 35

2 Answers2

2

SQL Fiddle:

SELECT a.columnA
FROM MyTable a
INNER JOIN MyTable b ON a.columnA = b.columnA 
WHERE a.columnB = 'abc'
AND b.columnB = 'pqr';
Linger
  • 14,942
  • 23
  • 52
  • 79
0
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.

Nick
  • 3,573
  • 12
  • 38
  • 43
  • Yes, this gave me all the duplicate entries. but my need is to find duplicate entries for two columnB entries. Thanks for the try. – Kalpesh Patel Jul 07 '14 at 12:30