tags:

views:

89

answers:

7
SELECT * FROM Questions 
INNER JOIN QuestionKeyword INNER JOIN Keywords
ON Questions.ID=QuestionKeyword.QuestionID 
AND QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'

It says: Incorrect syntax near the keyword 'WHERE'.

+6  A: 

You cannot combine the conditions from multiple JOINs but you have to list them separately with each join:

SELECT * FROM Questions 
INNER JOIN QuestionKeyword ON Questions.ID=QuestionKeyword.QuestionID
INNER JOIN Keywords  ON QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'
Henk Holterman
thanks man it worked :)
Ahmad Farid
+1  A: 

You've only got one ON clause and two INNER JOINs. For an INNER JOIN, join conditions with ON are mandatory. So the SQL parser is likely getting confused and seeing your WHEN unexpectedly.

Chris J
+3  A: 

You have two JOINs but only one ON. You probably want

SELECT
    *
FROM
    Questions
    INNER JOIN QuestionKeyword ON Questions.ID = QuestionKeyword.QuestionID
    INNER JOIN Keywords ON QuestionKeyword.KeywordID = Keywords.ID
WHERE
    Keywords.Keyword LIKE '%es%'
AakashM
+3  A: 

You're missing an "ON" after the first INNER JOIN.

SELECT * 
FROM Questions 
    INNER JOIN QuestionKeyword
        ON QuestionKeyword.QuestionID=Questions.ID
    INNER JOIN Keywords
        ON QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'
Rich Adams
+3  A: 

You must have an ON clause for each join you're doing. This should fix it:

SELECT * FROM Questions 
INNER JOIN QuestionKeyword 
ON Questions.ID=QuestionKeyword.QuestionID 
INNER JOIN Keywords
ON QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'

Edit: Damn, four other answers before I could finish typing! :P

Matt Sach
yeah man, stack overflow rocks ;)
Ahmad Farid
+2  A: 

Your INNER JOIN is messed up.

Something like this should work:

SELECT * FROM Questions 
INNER JOIN QuestionKeyword ON Questions.ID=QuestionKeyword.QuestionID 
INNER JOIN Keywords ON QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'
Colin Mackay
+2  A: 

Try rewriting it as:

SELECT *
FROM Questions
INNER JOIN QuestionKeyword ON Questions.ID=QuestionKeyword.QuestionID
INNER JOIN Keywords ON QuestionKeyword.KeywordID=Keywords.ID
WHERE Keywords.Keyword LIKE '%es%'

Each INNER JOIN requires a corresponding ON keyword and join condition.

Adamski