Jump to content

Recommended Posts

I'm trying to zero out products in my shop that don't have a match in two other tables.  When I run this query, it kills my MySql process load, and eventually crashes the server (500 error).

I'd appreciate any advice to run this better!

<?php
$query = "UPDATE shop_products p,inventory1 1,inventory2  2 
			SET 
					p.product_in_stock = '0' 
			WHERE 
					p.product_sku != 1.SKU 
			AND 
					p.product_sku != 2.PartNumber";
$result = mysql_query($query);

if (!$result) {
	throw new Exception('You fail: ' . mysql_error($db));
} else {
	echo "Inventory Updated";
}
?>

 

Just as a side note, I tried this as a SELECT statement in PHPMyAdmin, with very similar results.

SELECT product_sku,SKU,PartNumber 
FROM shop_products,inventory1,inventory2 
WHERE 
product_sku != SKU 
AND 
product_sku != PartNumber

Link to comment
https://forums.phpfreaks.com/topic/172200-update-one-table-from-two-others/
Share on other sites

UPDATE shop_products p,inventory1 i1,inventory2  i2

            SET

                  p.product_in_stock = '0'

            WHERE

                  p.product_sku != i1.SKU

            AND

                  p.product_sku != i2.PartNumber

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.