Ocean Sailor
7-10-03, 08:18 AM
I really need help, not a db guy..willing to learn hard. Going on the 7th week on this..&%#%.
Problem:
Updating a specific Table record (Inventory) from another table based on a conditional equal record (primaryKey) that exits in both tables.
--> Primary key used to find the records for both tables
--> compared the 2 table records based on the same primary key
--> updated specific records that are differnt in one table
Update Query Syntax (Anonymous help..thanks for it):
UPDATE {table-name}
SET {column-name} = {expression} [, {column-name} = {expression} ...] [WHERE {condition}]
Proposed Solution (not working):
UPDATE Table1
SET Quantity = (
SELECT Table2.Quantity
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
)
WHERE EXISTS (
SELECT *
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
AND Table1.Quantity <> Table2.Quantity
)
Error Message from MySQL:
/* Error : "You have an error in your SQL syntax near 'SELECT rsr23.Inventory FROM
rsr23 WHERE products.pID = rsr23.rsr ) WHERE EXISTS ( S' at line 1" */
So basicly the first line of the proposed solution, seems not to work in MySQL;
SET Quantity = (
SELECT Table2.Quantity
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
)
Ideas...Please:
Any help would be greatly rewarded....
thks...
Problem:
Updating a specific Table record (Inventory) from another table based on a conditional equal record (primaryKey) that exits in both tables.
--> Primary key used to find the records for both tables
--> compared the 2 table records based on the same primary key
--> updated specific records that are differnt in one table
Update Query Syntax (Anonymous help..thanks for it):
UPDATE {table-name}
SET {column-name} = {expression} [, {column-name} = {expression} ...] [WHERE {condition}]
Proposed Solution (not working):
UPDATE Table1
SET Quantity = (
SELECT Table2.Quantity
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
)
WHERE EXISTS (
SELECT *
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
AND Table1.Quantity <> Table2.Quantity
)
Error Message from MySQL:
/* Error : "You have an error in your SQL syntax near 'SELECT rsr23.Inventory FROM
rsr23 WHERE products.pID = rsr23.rsr ) WHERE EXISTS ( S' at line 1" */
So basicly the first line of the proposed solution, seems not to work in MySQL;
SET Quantity = (
SELECT Table2.Quantity
FROM Table2
WHERE Table1.PrimaryKey = Table2.PrimaryKey
)
Ideas...Please:
Any help would be greatly rewarded....
thks...