MySQL查询不起作用 - 无法找出原因

时间:2014-09-05 17:13:15

标签: mysql join

我有这个查询,我很确定它设置正确,但是当我知道应该返回1行时,它不会返回没有结果。

SELECT
    `t1`.id,
    `t1`.length,
    `t2`.last,
    `t2`.first,
    `t4`.name,
    `t5`.text
FROM `res` AS `t1`
INNER JOIN `pt` AS `t2`
     ON `t1`.ptid=`t2`.pt
INNER JOIN `docs` AS `t3`
     ON `t1`.doc=`t3`.did
LEFT JOIN `user` AS `t4`
     ON `t3`.user=`t4`.id
INNER JOIN `desc` AS `t5`
     ON `t1`.desc=`t5`.id

ORDER BY
     `t1`.date ASC

再次,没有得到错误 - 只是没有结果。

由于

1 个答案:

答案 0 :(得分:1)

desc是保留字。你需要在它周围加上反引号。

JOIN `desc` as `t5` ON `t1`.desc=`t5`.id

应该是

JOIN `desc` as `t5` ON `t1`.`desc`=`t5`.id