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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
This will delete all records from
t1that also exist int2, leaving you with a stripped-downt1, but possibly with records int2that don’t exist int1:*You may want to consider using
EXISTSinstead ofIN, as per Brian Hooper’s suggestion.This will combine the two tables into a third table (
t3), removing duplicates along the way: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:*The
DISTINCTkeyword is optional – it’s the default behaviour