What is wrong with this WHERE clause?
Is there a reason why this query doesn't work? The following query will work if I just exclude the WHERE clause. I need to know what is wrong with it. I know the given values of $key exists in the table, so why doesn't this work?
$q = "SELECT * WHERE t1.project=$key
FROM project_technologies AS t1
JOIN languages AS t2
ON t1.language = t2.key";
Table's have the following fields:
project_开发者_如何学Gotechnologies
- key - project - languagelanguages
- key - nameWHERE goes after FROM/JOIN.
SELECT *
FROM project_technologies AS t1
JOIN languages AS t2
ON t1.language = t2.key
WHERE t1.project=$key
SELECT * FROM project_technologies AS t1
JOIN languages AS t2
ON t1.language = t2.key
WHERE t1.project=$key
the where
should be at the end (after JOINs)
SELECT *
FROM project_technologies AS t1
JOIN languages AS t2
ON t1.language = t2.key
WHERE t1.project=$key
In SQL you write :
SELECT ... FROM tables ... WHERE conditions
You put the stuff in the wrong order...
The WHERE clause comes after the FROM clause.
SELECT *
FROM project_technologies as t1
JOIN languages as t2
on t1.language = ts.key
WHERE t1.project = $key
I think WHERE
has to come after FROM
. Have you tried this?
$q = "SELECT *
FROM project_technologies AS t1
JOIN languages AS t2
ON t1.language = t2.key
WHERE t1.project=$key";
"SELECT * FROM project_technologies AS t1 INNER JOIN languages AS t2 ON t1.language = t2.key WHERE t.project = '$key'";
FROM
comes before WHERE
in a SELECT
statement.
You should place your WHERE clause after your FROM clause.
Maybe this should be the right way to write it
"SELECT * FROM project_technologies AS t1 JOIN languages AS t2 ON t1.language = t2.key WHERE t1.project=$key";
精彩评论