In mysql I have this query
SELECT m.*
FROM members m
RIGHT JOIN (SELECT
IF(`from member_id`=1, `to member_id`, `from member_id`) as other_id, text, `date sent`
FROM message
WHERE ((`from member_id`=1 AND `to member_id`=m.id) OR (`to member_id`=1 OR `from member_id`=m.id))
ORDER BY `date sent` DESC
LIMIT 1
) as t on 1=1
ORDER BY t.`date sent` DESC
and I'm getting this error:
Unknown column 'm.id' in 'where clause'
How can I pass the members column value in the sub query select statement?
I am creating this sub query so it evaluates to 1 row, then I want to attach it to the right of the outer select statement.
Thanks.