tags:

views:

113

answers:

10

is there a reason why this query wouldn'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 values of $key given exist in the table so why wouldn't this work?

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

each table has the following fields.
project_technologies
- key
- project
- language
languages
- key
- name

+1  A: 

FROM Comes before WHERE.

Faruz
+1  A: 
"SELECT * FROM project_technologies AS t1  INNER JOIN languages AS t2 ON t1.language = t2.key WHERE t.project = '$key'";
TIMEX
+5  A: 
SELECT *
            FROM project_technologies AS t1
            JOIN languages AS t2
            ON t1.language = t2.key
            WHERE t1.project=$key
brysseldorf
A: 

You should place your WHERE clause after your FROM clause.

Augenfeind
+6  A: 
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)

najmeddine
+3  A: 

In SQL you write :

SELECT ... FROM tables ... WHERE conditions

You put the stuff in the wrong order...

peufeu
+6  A: 

WHERE goes after FROM/JOIN.

SELECT    * 
FROM      project_technologies AS t1
JOIN      languages AS t2
ON        t1.language = t2.key
WHERE     t1.project=$key
Maximilian Mayerl
+3  A: 

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
Josh Smeaton
+3  A: 

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";
Paul Stephenson
A: 

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";
Lex