Jump to content

compare 2 tables - output the difference


quasiman

Recommended Posts

I have 2 tables, with some of the same information in each. For instance, they both have a primary key (although different numbers for each), a SKU number, quantity, etc, etc.

 

I'm using an UPDATE script to change available quantities as a means of formatting the data I get from my suppliers.

 

So when I get new products in the data sheet, I want to know about it. I want to know what is in the new table and not in my shop database, so that I can manually add records to the proper categories.

 

$query = "select new_data.SKU from new_data left outer
  join shop_items on shop_items.ItemSKU = new_data.SKU
where shop_items.ItemSKU is null";

    $result = mysql_query($query) or die(mysql_error());

    while($row = mysql_fetch_array($result)){

        echo $row['SKU'];
        echo "<br />";
    } 

 

For some reason it's taking forever to finish. I ran a test through PHPEdit and it timed out at:

$result = mysql_query($query) or die(mysql_error());

 

If I reverse the query, listing all products in the shop and not the incoming inventory list, then everything runs very quickly.

 

So I'm wondering if the table construction has anything to do with it? For instance, the shop items table has an item ID as the primary key, then the SKU numbers. I don't get my inventory lists with item ID's so I set the incoming table to use the SKU as the primary key (obviously not auto_increment).

 

Any thoughts or suggestions?

Link to comment
https://forums.phpfreaks.com/topic/48994-compare-2-tables-output-the-difference/
Share on other sites

I am not sure what u want but try this one;

 

$query = "select new_data.SKU from new_data left outer
  join shop_items on shop_items.ItemSKU = new_data.SKU
where shop_items.ItemSKU='null'";

    $result = mysql_query($query) or die(mysql_error());

    while($row = mysql_fetch_array($result)){

        echo $row['SKU'];
        echo "<br />";
    } 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.