Comparing Two Tables and Deleting duplicate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nhatto
    New Member
    • Nov 2009
    • 3

    Comparing Two Tables and Deleting duplicate

    Hello

    I have Two Tables ( Table A and Table B)

    Table A has one field : email
    Table B has three Fields : First name, Last name , email

    I want to check if the email in Table B is found in Table A, And if it is , then I want to delete the row ( First name, Last name , email ) from Table B that has that email.

    any help is really appreciated and thank you in advance!
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    A sub-query is probably the easiest to understand
    Code:
    DELETE FROM tableA WHERE email IN (SELECT email FROM tableB)
    or something like that.
    But test first using
    Code:
    SELECT * FROM tableA WHERE email IN (SELECT email FROM tableB)
    [/CODE]

    Comment

    • nhatto
      New Member
      • Nov 2009
      • 3

      #3
      Keep getting an error

      Hello,

      Thank you for your response

      when i try to run the query, I keep getting the following error:

      #1267 - Illegal mix of collations (latin1_swedish _ci,IMPLICIT) and (armscii8_bin,I MPLICIT) for operation '='

      I have no clue what that means? any idea?

      Comment

      • nhatto
        New Member
        • Nov 2009
        • 3

        #4
        Found why

        I found why this is the error :

        the reason was the Collation were not matching for both fields..

        got it fixed.. and it worked beautifully

        thank you so much !

        Comment

        • PreethiBugs
          New Member
          • Sep 2014
          • 1

          #5
          Work fine... thank you for great job

          Originally posted by code green
          A sub-query is probably the easiest to understand
          Code:
          DELETE FROM tableA WHERE email IN (SELECT email FROM tableB)
          or something like that.
          But test first using
          Code:
          SELECT * FROM tableA WHERE email IN (SELECT email FROM tableB)
          [/CODE]
          Work fine... thank you for great job

          Comment

          • romiardisaja
            New Member
            • Jun 2019
            • 1

            #6
            Worked for me, thank you...

            Comment

            • gosai jahnvi
              New Member
              • Apr 2019
              • 22

              #7
              You can try this, I hope it will assist you.

              Code:
              DELETE table1 
              FROM table1 
              INNER JOIN table2 ON table1.name = table2.name
              WHERE table1.id = table2.id
              thank you.

              Comment

              • shivkumar1
                New Member
                • May 2019
                • 4

                #8
                Code:
                DELETE a
                FROM a  -- first table
                INNER JOIN b -- second table
                      ON b.ID = a.ID
                      AND b.Name = a.Name
                      AND b.Foo = a.Foo
                      AND b.Bar = a.Bar
                That should do it... there is also CHECKSUM(*), but this only helps - you'd still need to check the actual values to preclude hash-conflicts.
                Last edited by gits; Aug 19 '19, 09:56 AM. Reason: please use code tags

                Comment

                Working...