I wish to update an empty field using data from another table

Go To StackoverFlow.com

0

I used the SELECT COUNT(*) to check my WHERE statement and got the correct number of updates, however when I attempt the UPDATE I get a syntax error around line 3.

UPDATE scans AS s
SET s.sbjnum = d.sbjnum
JOIN details AS d on d.name = s.name
WHERE s.sbjnum =''
2012-04-04 18:27
by user1289049


1

You have to have a FROM to have a JOIN

UPDATE scans 
SET sbjnum = d.sbjnum 
FROM scans s
JOIN details AS d ON d.name = s.name 
WHERE s.sbjnum =''

According to the MySQL manual you can write it like this:

UPDATE scans AS s
JOIN details AS d ON d.name = s.name 
SET sbjnum = d.sbjnum 
WHERE s.sbjnum =''
2012-04-04 18:30
by GavinCattell
Ads