INNER JOIN错误

时间:2013-01-11 10:45:30

标签: php mysql sql

出于某种原因,我的INNER JOIN出现问题,但它根本不起作用。

这是我的代码

SELECT
    `hold`.`id` AS `id`,
`hold`.`name` AS `name`
INNER JOIN `instruktorer`
ON `hold`.`ins` = `instruktorer`.`id`
FROM `hold`

我得到的错误是:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN `instruktorer` ON `hold`.`ins` = `instruktorer`.`id` FROM `hold`' at line 4

我几乎每天都会进行INNER JOIN,但现在我无法让它工作。

希望有人可以帮助我

3 个答案:

答案 0 :(得分:3)

试试这个:

SELECT
    `hold`.`id` AS `id`,
`hold`.`name` AS `name`
FROM `hold`
INNER JOIN `instruktorer`
ON `hold`.`ins` = `instruktorer`.`id`

答案 1 :(得分:1)

FROM必须在INNER JOIN之前出现。通常,所有查询都有定义的顺序。对于SELECT,它就像这样

select
from
join
where
group by
having
order by 
limit

答案 2 :(得分:1)

写JOIN的格式不正确。它应该如下 SELECT'column_name'..... FROM'table1'JOIN TYPE'table2'ON SOME CONDITION

请检查基础知识here