Duplicate search for lname

Results 1 to 2 of 2

Thread: Duplicate search for lname

  1. #1
    Join Date
    Dec 1969

    Default Duplicate search for lname

    How do you write a SQL query to check for any duplicate data (last names) in a certain field (lname)?<BR>This table has a primary field (prsn_pk)<BR><BR>I tried this but it still returned all rows?<BR><BR>(SELECT prsn_pk,lname<BR>From tablename<BR>WHERE Exists (SELECT lname, Count(tablename.prsn_pk)<BR>FROM tablename<BR>WHERE tablename.lname = f.lname<BR>GROUP BY tablename.lname<BR>HAVING Count(tablename.prsn_pk) &#062; 1))<BR>

  2. #2
    Join Date
    Dec 1969


    But watch out: SELECT DISTINCT &#060;list of fields&#062; will eliminate duplicates *ONLY* if every field in the list of fields is the same.<BR><BR>So if you do<BR><BR>SELECT DISTINCT person, email ... GROUP BY person, email<BR><BR>the person *will* show up twice if he is in the table twice with two different email values.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts