Jump to content

LEFT JOIN trouble


TheEvilMonkeyMan

Recommended Posts

Hey,

I'm having trouble with this query that's supposed to left join an 'answer' row to a 'question' row but I keep getting "Unknown column q.id in 'on clause'". Here's the query:

 

 

SELECT *
FROM questions_new AS q, questions_map_domains AS map
LEFT JOIN answers AS ans
ON (ans.question_id = q.id)
WHERE q.id = map.question_id
AND map.domain_id = $domain_id

 

Link to comment
https://forums.phpfreaks.com/topic/219437-left-join-trouble/
Share on other sites

Ah, I fixed it! Thanks for your reply

 

SELECT q.*, ans.content AS answer
FROM questions_map_domains AS map, questions_new AS q
LEFT JOIN answers AS ans
ON (ans.question_id = q.id)
WHERE q.id = map.question_id
AND map.domain_id = $domain_id
AND q.down_votes < 3
ORDER BY q.up_votes DESC, q.down_votes ASC
LIMIT 10

Link to comment
https://forums.phpfreaks.com/topic/219437-left-join-trouble/#findComment-1138280
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.