You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL语法错误排查请求:多表查询WHERE子句报1064错误

Fixing Your MySQL 1064 Syntax Error

Hey there! That 1064 error is a classic syntax red flag, and I can spot the exact issue right away. Let's walk through fixing it.

The Root Problem

In your WHERE clause, you're using commas to separate table join conditions (like destination.destination_id=flights.d_id, plane.plane_id=flights.p_id). MySQL doesn't accept commas as condition separators here—you need to use AND to link those equality checks properly.

Quick Fix (Sticking to Your Original Structure)

Here's the corrected query with commas replaced by AND in the WHERE clause:

SELECT 
  `traveller`.`ticket_no`,
  `traveller`.`fname`,
  `traveller`.`lname`,
  `destination`.`d_name`,
  `plane`.`plane_name`,
  `flights`.`flight_name` 
FROM 
  `traveller`,
  `destination`,
  `flights`,
  `plane`,
  `checked` 
WHERE 
  `destination`.`destination_id` = `flights`.`d_id`
  AND `plane`.`plane_id` = `flights`.`p_id`
  AND `checked`.`flight_id` = `flights`.`flight_id`
  AND `checked`.`t_id` = `traveller`.`ticket_no` 
  AND `traveller`.`ticket_no` = "1"

Better Practice: Use Explicit JOIN Syntax

While the quick fix works, using explicit JOIN clauses makes your query way more readable and avoids accidental cross joins. Here's the same logic rewritten with modern, standard JOIN syntax (I also added table aliases to clean things up):

SELECT 
  t.ticket_no,
  t.fname,
  t.lname,
  d.d_name,
  p.plane_name,
  f.flight_name 
FROM 
  `traveller` t
  JOIN `checked` c ON c.t_id = t.ticket_no
  JOIN `flights` f ON c.flight_id = f.flight_id
  JOIN `destination` d ON d.destination_id = f.d_id
  JOIN `plane` p ON p.plane_id = f.p_id
WHERE 
  t.ticket_no = "1"

Either version should resolve that 1064 error for you. Let me know if you hit any other snags!

内容的提问来源于stack exchange,提问作者Anubis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:28:39