tags:

views:

47

answers:

4
    SELECT * FROM ExternalQuestionKeyword INNER JOIN ExternalKeywords 
ON ExternalKeywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE QuestionID = 17
A: 
SELECT * FROM ExternalQuestionKeyword INNER JOIN Keywords ON Keywords.ID=ExternalQuestionKeyword.KeywordID  WHERE QuestionID = 17
madcolor
+1  A: 

Should be:

SELECT * FROM ExternalQuestionKeyword INNER JOIN ExternalKeywords 
ON ExternalKeywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE QuestionID = 17

Or

SELECT * FROM ExternalQuestionKeyword INNER JOIN Keywords 
ON Keywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE QuestionID = 17
Brisbe42
but the second one gets different results
Ahmad Farid
The second one gets different results because your question was unclear on whether Keywords or ExternalKeywords was the real name of the table--we gave two versions, one of which would work if it was Keywords, and one that would work if it was ExternalKeywords. By necessity, one of the two had to be wrong! ;)
Brisbe42
yes man, that was a mistake due to copy paste. thanks, i modified it now :)
Ahmad Farid
A: 
SELECT * FROM ExternalQuestionKeyword INNER JOIN ExternalKeywords 
ON ExternalKeywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE QuestionID = 17

Or

SELECT * FROM ExternalQuestionKeyword INNER JOIN Keywords 
ON Keywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE QuestionID = 17
Developer Art
but the second one gets different results
Ahmad Farid
@Ahmad Farid: From your question it was clear it was just a matter of typo, but it was not possible to say which way without knowing your data model. So I offered two possible options I could come up with based on the amount of information you provided.
Developer Art
yes man, that was a mistake due to copy paste. thanks, i modified it now :)
Ahmad Farid
A: 

Where is the table/alias for ExternalKeywords? There isn't one in the code and that's where the error is coming from, as you are attempting a join on the id field of ExternalKeywords

Looks like it should be

SELECT 
    * 
FROM 
    ExternalQuestionKeyword 
INNER JOIN 
    Keywords 
    ON 
        Keywords.ID=ExternalQuestionKeyword.KeywordID  
WHERE 
    QuestionID = 17
Russ Cam