Entry
How can I compare two queries that are generated from a MySQL database and specify the differences on the page shown to the page viewer?
Jul 17th, 2000 14:39
Chris Sigmon, Matt Gregory, Ben Udall,
There are numerous ways to compare data, from writing functions into
your program to java to queries. I have found that queries are the
simplest, especially if you have many to perform. I utilize them in a
content management system that validates a live table to the staging
table using MySQL and PHP.
All you have to do is a left join. Below is an example that will tell
you where one record exists on one database, but not on the other.
SELECT tbl_stuff_stage.* FROM tbl_stuff_stage LEFT JOIN tbl_stuff_live
ON tbl_stuff_stage.stuff_id=tbl_stuff_live.stuff_id where
tbl_stuff.stuff_id is NULL
If you want to find out if anything has changed from one table to
another, here is an example.
SELECT tbl_stuff_stage.* FROM tbl_stuff_stage LEFT JOIN tbl_stuff_live
ON tbl_stuff_stage.stuff_id=tbl_stuff_live.stuff_id where
tbl_stuff_stage.stuff_name <> tbl_stuff_live.stuff_name OR
etc... (you can add as many <> as required, but it will slow down your
query
If you need any help just let me know