MySQL: Use CASE/ELSE value as join parameter

Posted by DRJ on Stack Overflow See other posts from Stack Overflow or by DRJ
Published on 2010-05-03T22:13:56Z Indexed on 2010/05/03 22:18 UTC
Read the original article Hit count: 165

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql