这个WHERE子句有什么问题?

时间:2009-10-22 09:01:15

标签: php mysql

这个查询不起作用的原因是什么?如果我只是排除WHERE子句,以下查询将起作用。我需要知道它有什么问题。我知道表中存在$ key的给定值,为什么这不起作用呢?

$q =   "SELECT * WHERE t1.project=$key
            FROM project_technologies AS t1
            JOIN languages AS t2
            ON t1.language = t2.key";

表格包含以下字段:

project_technologies
- 键
- 项目
- 语言

语言
- 键
- 姓名

10 个答案:

答案 0 :(得分:6)

SELECT * FROM project_technologies AS t1
JOIN languages AS t2
  ON t1.language = t2.key
WHERE t1.project=$key

where应该在最后(在JOIN之后)

答案 1 :(得分:6)

在FROM / JOIN之后的地方。

SELECT    * 
FROM      project_technologies AS t1
JOIN      languages AS t2
ON        t1.language = t2.key
WHERE     t1.project=$key

答案 2 :(得分:5)

SELECT *
            FROM project_technologies AS t1
            JOIN languages AS t2
            ON t1.language = t2.key
            WHERE t1.project=$key

答案 3 :(得分:3)

在SQL中你写:

SELECT ... FROM tables ... WHERE condition

你把东西放错了......

答案 4 :(得分:3)

WHERE子句位于FROM子句之后。

SELECT *
FROM project_technologies as t1
JOIN languages as t2
on t1.language = ts.key
WHERE t1.project = $key

答案 5 :(得分:3)

我认为WHERE必须在FROM之后。你试过这个吗?

$q =   "SELECT *
            FROM project_technologies AS t1
            JOIN languages AS t2
            ON t1.language = t2.key
            WHERE t1.project=$key";

答案 6 :(得分:1)

FROM位于WHERE声明中SELECT之前。

答案 7 :(得分:1)

"SELECT * FROM project_technologies AS t1  INNER JOIN languages AS t2 ON t1.language = t2.key WHERE t.project = '$key'";

答案 8 :(得分:0)

您应该在FROM子句之后放置WHERE子句。

答案 9 :(得分:0)

也许这应该是写它的正确方法

"SELECT * FROM project_technologies AS t1 JOIN languages AS t2 ON t1.language = t2.key WHERE t1.project=$key";