Home > Database > Mysql Tutorial > Why Does My MySQL UPDATE Query with INNER JOIN Produce a Syntax Error?

Why Does My MySQL UPDATE Query with INNER JOIN Produce a Syntax Error?

Mary-Kate Olsen
Release: 2024-12-11 03:38:10
Original
931 people have browsed it

Why Does My MySQL UPDATE Query with INNER JOIN Produce a Syntax Error?

Update Query Using Inner Join with MySQL: Troubleshooting a Syntax Error

You encounter a syntax error when executing the following MySQL update query:

UPDATE b
SET b.mapx = g.latitude,
    b.mapy = g.longitude
FROM business AS b
INNER JOIN business_geocode g ON b.business_id = g.business_id
WHERE (b.mapx = '' OR b.mapx = 0) AND
      g.latitude > 0
Copy after login

Here's a revised version of your query that should eliminate the syntax error:

UPDATE business AS b
INNER JOIN business_geocode AS g ON b.business_id = g.business_id
SET b.mapx = g.latitude,
  b.mapy = g.longitude
WHERE (b.mapx = '' OR b.mapx = 0) AND
  g.latitude > 0
Copy after login

Assessment

The original query had the table alias incorrectly defined for the business table; it should have been b in your query as you have it there. That was the only syntax issue.

Additional Notes

Your error message is missing. Providing it would help pinpoint the exact cause of the issue. Additionally, verify that the field types in your tables (e.g., mapx and mapy) match the data you're trying to insert.

The above is the detailed content of Why Does My MySQL UPDATE Query with INNER JOIN Produce a Syntax Error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template