Jump to content

[SOLVED] join tables error


quasiman

Recommended Posts

I've got something backwards here, and I can't see what it is.

I have two tables: products and inventory.  Products contains most of the information about the product, inventory contains the same SKU ID, the actual number of products onhand, and prices.
I'm trying to update the products table with the inventory tables on hand amount.

[code]<?php

mysql_connect("localhost", "LOGIN", "PASSWORD");

mysql_select_db("DATABASE");


$results = mysql_query("UPDATE PRODUCTS SET onhand = INVENTORY.onhand FROM INVENTORY JOIN INVENTORY ON INVENTORY.sku = PRODUCTS.sku")
or die(mysql_error());
?>[/code]

Any help would be greatly appreciated!
Link to comment
Share on other sites

Try this:

[code=php:0]UPDATE PRODUCTS SET onhand = INVENTORY.onhand FROM INVENTORY WHERE INVENTORY.sku = PRODUCTS.sku[/code]


You don't need to join in this case.  What you're doing is more like "SELECT INVENTORY.onhand FROM INVENTORY WHERE INVENTORY.sku = PRODUCTS.sku" for each row of PRODUCTS.
Link to comment
Share on other sites

hmm...I'm getting basically the same error:
[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM INVENTORY WHERE PRODUCTS.sku = INVENTORY.sku' at line 1[/quote]

I'm really not seeing anything wrong with this:
[code]<?php

mysql_connect("localhost", "LOGIN", "PASSWORD");

mysql_select_db("DATABASE");


mysql_query("UPDATE PRODUCTS SET onhand = INVENTORY.onhand FROM INVENTORY WHERE PRODUCTS.sku = INVENTORY.sku")
or die(mysql_error());
?>[/code]
Link to comment
Share on other sites

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.