Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Agh...getting error when referring to two tables

Status
Not open for further replies.

dcnguyen

Technical User
Mar 22, 2005
54
0
0
US
OK, I thought updating a table based on values from another would be as easy as this:

UPDATE table1 SET table1.apples = table2.apples WHERE table1.oranges = table2.oranges

Those columns definitely exist. But I keep getting this error:

#1054 - Unknown column 'table2.oranges' in 'where clause'


Is there some archaic error I'm making?
 
Try this:

UPDATE table1 SET table1.apples = (select table2.apples from table2) WHERE table1.oranges = table2.oranges
 
Thanks...that took out the error message, but it returns 0 rows as affected, even though I know for sure there are matching entries.
 
Maybe the UPDATE aTable ... FROM aTable JOIN bTable syntax will work.
Code:
UPDATE table1 SET table1.apples = table2.apples
FROM table1
JOIN table2 ON table1.oranges = table2.oranges
 
oohhhhh...ok, I was wondering about the error message I got. I just gave up. Thanks for the help all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top