faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 17 people (71%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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