Home > Database > Mysql Tutorial > How to Fix the 'MySQL unknown column in ON clause' Error?

How to Fix the 'MySQL unknown column in ON clause' Error?

Patricia Arquette
Release: 2025-01-13 06:49:42
Original
450 people have browsed it

How to Fix the

Troubleshooting the MySQL "Unknown column in ON clause" Error

MySQL's "#1054 - Unknown column '...' in 'on clause'" error typically indicates a problem with your SQL query's join syntax. This often occurs when you combine comma-style joins with the more modern ANSI-92 JOIN syntax. The database interprets the join order inconsistently, resulting in the error.

The solution is to standardize your join method. Avoid mixing styles; instead, consistently use the ANSI-92 JOIN keyword for all joins in your query.

Here's an example demonstrating the correction:

<code class="language-sql">SELECT p.*,
       IF(COUNT(ms.PropertyID) > 0, 1, 0) AS Contacted,
       pm.MediaID,
       DATE_FORMAT(p.AvailableFrom, '%d %b %Y') AS AvailableFrom,
       AsText(pg.Geometry) AS Geometry
FROM property p
JOIN propertygeometry pg ON p.PropertyGeometryID = pg.id
JOIN shortlist sl ON sl.PropertyID = p.id AND sl.MemberID = 384216
LEFT JOIN message ms ON ms.PropertyID = p.id AND ms.SenderID = 384216
LEFT JOIN property_media pm ON pm.PropertyID = p.id AND pm.IsPrimary = 1
WHERE p.paused = 0
GROUP BY p.id;</code>
Copy after login

By adhering to this consistent JOIN syntax, you'll prevent the "Unknown column in ON clause" error and ensure your MySQL queries execute correctly.

The above is the detailed content of How to Fix the 'MySQL unknown column in ON clause' 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