Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.