SQL query to return all rows containing duplicate data from one field

I have a table with card numbers and names. Some of these names are the same, that is, they have multiple cards. How can I select all rows where the name appears more than once?

+2


a source to share


5 answers


The following might be the solution you are looking for



Select * from CardTable where cardid in ( select cardid from CardTable group by cardid having count(cardid) > 1)

      

+4


a source


Using:



  SELECT t.name
    FROM TABLE t
GROUP BY t.name
  HAVING COUNT(*) > 1

      

+2


a source


The following should work:

SELECT        * 
FROM cards    c1 
INNER JOIN    cards c2 on c1.name = c2.name 
WHERE         c2.id <> c1.id

      

+1


a source


select count(*) as n, [name]
from table1
group by [name]
having n > 1

      

0


a source


if you want whole lines here is a solution that will work for sql 7 and up

SELECT t1.* FROM(
 SELECT t.name
    FROM YourTable t
GROUP BY t.name
  HAVING COUNT(*) > 1) t2
  JOIN YourTable t1 on t2.name = t1.name

      

0


a source







All Articles