MySQL: Use CASE/ELSE value as join parameter
- by DRJ
I'm trying to join the NAME and PHOTO from USERS table to the TRANSACTIONS table based on who is the payer or payee. It keeps telling me can't find the table this -- What am I doing wrong?
SELECT name,photo,amount,comment,
(
CASE payer_id
WHEN 72823 THEN payee_id
ELSE payer_id
END
) AS this
FROM transactions
RIGHT JOIN users ON (users.id=this)
WHERE payee_id=72823 OR payer_id=72823