SELECT * FROM ExternalQuestionKeyword INNER JOIN ExternalKeywords
ON ExternalKeywords.ID=ExternalQuestionKeyword.KeywordID
WHERE QuestionID = 17
views:
47answers:
4
A:
SELECT * FROM ExternalQuestionKeyword INNER JOIN Keywords ON Keywords.ID=ExternalQuestionKeyword.KeywordID WHERE QuestionID = 17
madcolor
2009-08-28 16:08:34
+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
2009-08-28 16:09:00
but the second one gets different results
Ahmad Farid
2009-08-28 16:17:01
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
2009-08-28 16:19:43
yes man, that was a mistake due to copy paste. thanks, i modified it now :)
Ahmad Farid
2009-08-28 16:22:48
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
2009-08-28 16:09:16
@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
2009-08-28 16:22:56
yes man, that was a mistake due to copy paste. thanks, i modified it now :)
Ahmad Farid
2009-08-28 16:31:02
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
2009-08-28 16:09:54