Why is sm.status_id and sm.user_id getting an unknown column error? I don’t usually use the JOIN keyword for table joins.
...
FROM questions q, connections sm
JOIN users u ON q.user_id = u.id
JOIN users lu ON q.last_user = lu.id
JOIN (SELECT q2.id FROM questions q2 WHERE q2.status_id = sm.status_id LIMIT 2) x ON x.id = q.id
WHERE sm.user_id = 38
GROUP BY th.id
You have a few issues with your current query.
First, you are mixing
JOINsyntax. You have both comma separated values and then joins with anONcondition.Second, you are attempting to access an alias for a table in an inner subquery which you cannot do.
My suggestion is to try something like this:
You did not post your
SELECTlist but if you want to include fields from theconnectionstable in theselectlist then you will need to join on it again or include the fields in the subquery.