我对简单查询有点问题。这是:
SELECT `T_COURS`.`COU_DATE`,
`T_SESSIONS`.*,
`T_FORMATIONS`.`FOR_TITRE`, `T_FORMATIONS`.`FOR_ID`, `T_FORMATIONS`.`FOR_TITRE`, `T_FORMATIONS`.`FOR_CATEGORIE`,
`T_FORMATIONS`.`FOR_DESCRIPTION`, `T_FORMATIONS`.`FOR_MIN_PART`, `T_FORMATIONS`.`FOR_MAX_PART`, `T_FORMATIONS`.`FOR_PRIX`, `T_FORMATIONS`.`FOR_LANGUE`
FROM `T_FORMATIONS`
INNER JOIN `T_COURS` ON `T_SESSIONS`.`SES_ID` = `T_COURS`.`COU_SES_ID`
INNER JOIN `T_SESSIONS` ON `T_FORMATIONS`.`FOR_ID` = `T_SESSIONS`.`SES_FOR_ID`
WHERE `T_SESSIONS`.`SES_ETAT` = 1
ORDER BY `T_COURS`.`COU_DATE` ASC, `T_SESSIONS`.`SES_TITRE` ASC, `T_FORMATIONS`.`FOR_TITRE` ASC LIMIT 5
当我尝试运行它时,我收到此消息:
#1054 - Unknown column 'T_SESSIONS.SES_ID' in 'on clause'
我真的不明白为什么因为我的数据库中存在所有内容?
我在互联网上寻找答案,但它对我没有帮助(或者我没有理解我读到的答案)。
答案 0 :(得分:0)
如果没有看到您的完整表格结构,我会首先交换您的JOIN
订单,在您尝试在当前版本中使用它之后加入T_SESSIONS
。你现在有:
FROM `T_FORMATIONS`
INNER JOIN `T_COURS`
ON `T_SESSIONS`.`SES_ID` = `T_COURS`.`COU_SES_ID`
INNER JOIN `T_SESSIONS`
ON `T_FORMATIONS`.`FOR_ID` = `T_SESSIONS`.`SES_FOR_ID`
将其更改为:
FROM `T_FORMATIONS`
INNER JOIN `T_SESSIONS`
ON `T_FORMATIONS`.`FOR_ID` = `T_SESSIONS`.`SES_FOR_ID`
INNER JOIN `T_COURS`
ON `T_SESSIONS`.`SES_ID` = `T_COURS`.`COU_SES_ID`
完整查询:
SELECT `T_COURS`.`COU_DATE`,
`T_SESSIONS`.*,
`T_FORMATIONS`.`FOR_TITRE`,
`T_FORMATIONS`.`FOR_ID`,
`T_FORMATIONS`.`FOR_TITRE`,
`T_FORMATIONS`.`FOR_CATEGORIE`,
`T_FORMATIONS`.`FOR_DESCRIPTION`,
`T_FORMATIONS`.`FOR_MIN_PART`,
`T_FORMATIONS`.`FOR_MAX_PART`,
`T_FORMATIONS`.`FOR_PRIX`,
`T_FORMATIONS`.`FOR_LANGUE`
FROM `T_FORMATIONS`
INNER JOIN `T_SESSIONS`
ON `T_FORMATIONS`.`FOR_ID` = `T_SESSIONS`.`SES_FOR_ID`
INNER JOIN `T_COURS`
ON `T_SESSIONS`.`SES_ID` = `T_COURS`.`COU_SES_ID`
WHERE `T_SESSIONS`.`SES_ETAT` = 1
ORDER BY `T_COURS`.`COU_DATE` ASC, `T_SESSIONS`.`SES_TITRE` ASC, `T_FORMATIONS`.`FOR_TITRE` ASC
LIMIT 5