
MYSQL Update Statement Inner Join Tables?
1 Expert Answer
For Your case, you have Correlated Tables. You wil need to use Subquery to achieve your objective.
SQL allows you to use Subquery in the 'UPDATE' 'SET' or 'WHERE clause
For your case, you can use subquery in the ''SET' statement as shown below:
UPDATE business b
SET mapx = (
SELECT g.latitude FROM business_geocode g WHERE b.business_id = g.business_id
AND (b.mapx = '' or b.mapx = 0)
AND g.latitude > 0
) ,
mapy = (
SELECT g.longitude FROM business_geocode g WHERE b.business_id = g.business_id
AND (b.mapx = '' or b.mapx = 0)
AND g.latitude > 0
)
WHERE (b.mapx = '' or b.mapx = 0) ;
Hope this helps.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Matt S.
05/20/19