Feb
1
Compare Two MySQL Tables
Posted by john in mysql

The other day I needed to compare two tables and see what data was in one but not in the other.

table_a is my main table that I want to update and table_b is my storage table that I have my updates in. The query below will return all records that are in table_b, but no in table_a.


SELECT table_b.* FROM table_b
LEFT JOIN table_a ON table_b.id = table_a.id
WHERE table_a.item_id IS NULL

The you can take those results and use them to INSERT the missing records.

This is the best way I can think of. If anyone has a better way, please leave a comment on how you would recommend.

One Response to “Compare Two MySQL Tables”

Palmetto Says:

This is palmetto from digg.. thanks for the info about myphpadmin and mysql.

@palmetto - if you’ve already got a site and a company with PHP & MySQL hosting your site, hop on over to http://www.linein.org/blog/ and post a comment with your email address. I’d be more than happy to help. Both are really easy to setup and get started.

thanks for the help.. I will be learning now. ;)

[Reply]

Leave a Reply