如何解决此问题:
Unknown column 'exdays_relation.exercise_id' in 'on clause'
SELECT * FROM
`user_days`
LEFT JOIN `menu` ON `menu`.`id` = `exdays_relation`.`exercise_id`
JOIN `exdays_relation` ON `exdays_relation`.`day_id` = `user_days`.`day_id`
WHERE `user_days`.`for_date` LIKE '2016-12-12'
查询关系:
menu
-------
id int(11) PK AUTO_INCREMENT
exdays_relation
-------------------
exdaysrel_id int(11) PK AUTO_INCREMENT
exercise_id int(11) FK from id(menu)
day_id int(11) FK from day_id(user_days)
user_days
-----------------
day_id int(11) PK
for_date date
答案 0 :(得分:2)
因为您JOIN
和user_days
表menu
,但提到exdays_relation
`user_days`
LEFT JOIN `menu` ON `menu`.`id` = `exdays_relation`.`exercise_id`
您需要提及正在加入的表中的列,您不能在别处提及列名。
答案 1 :(得分:1)
切换连接。第一个连接使用尚未连接的表
SELECT *
FROM user_days
JOIN exdays_relation ON exdays_relation.day_id = user_days.day_id
LEFT JOIN menu ON menu.id = exdays_relation.exercise_id
WHERE user_days.for_date = '2016-12-12'