Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:30:15+00:00 2026-05-15T16:30:15+00:00

Guys, I have two basic tables ( id , first_name ). I want to

  • 0

Guys, I have two basic tables (id, first_name).

I want to run table 1 against table 2, delete duplicates, and spit out the cleansed version of table 1.

What’s the easiest way to do this with PHP/MySQL?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:30:16+00:00Added an answer on May 15, 2026 at 4:30 pm

    This will delete all records from t1 that also exist in t2, leaving you with a stripped-down t1, but possibly with records in t2 that don’t exist in t1:

    DELETE FROM table1 t1
    WHERE t1.id IN
        (SELECT id from table2 t2
            WHERE t2.id = t1.id AND t2.first_name = t1.first_name
        )
    

    *You may want to consider using EXISTS instead of IN, as per Brian Hooper’s suggestion.

    This will combine the two tables into a third table (t3), removing duplicates along the way:

    SELECT * INTO t3 
    FROM t1 UNION SELECT * FROM t2
    

    That will work for SQL Server (definitely) and MySQL (I think) but MySQL supports CREATE TABLE table_name AS select-statement, so you could use:

    CREATE TABLE t3 AS
    (SELECT * FROM t1 UNION DISTINCT SELECT * FROM t2)
    

    *The DISTINCT keyword is optional – it’s the default behaviour

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Guys I have two tables table B has a many to 1 relationship
Hi guys i have my array below and i want to retrieve two rows:as
Hi Guys i have two tables which look like this usertable RoleTable ----------------------- ---------------------------
Ok guys, so I'm making a scheduler. So I have two tables so far,
guys I have two question to ask, they're easy, but bothering me for a
hi guys i have two pipe delimited files,first file contains 1000 records and second
guys, I wrote a function to test if two inputs (a and b) have
Hey guys i have two date inputs containing three dropboxes for day,month and year
guys. I have two view controllers with two uiwebviews. Here is my code: First
Hey guys, so I have two models in my project, grinders, and votes. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.