php - Join two tables on the basis of two case obtained from parent table -


i have coin table provides information uploaded coins, , there owner table gives information owner of particular coin. in coin_owners table, there field 'ownership_mode' either 'transfer' or 'reward'. if mode 'transfer', want left join transfer table, , if mode 'reward', want join rewards table.

i have tried using case clause, it's not working.

the query tried is:

select * , coins.id coinid coins left join coin_owners on coin_owners.coin_id = coins.id left join (case when coin_owners.`ownership_mode` = 'transfer' transfer_detail on   transfer_detail.transfer_to = coin_owners.current_owner , transfer_detail.transfer_from = substring_index( coin_owners.previous_owner,  ',',  '-1' )   when coin_owners.`ownership_mode` = 'reward' rewards on rewards.`coin_ids` = coin_owners.coin_id , coin_owners.`ownership_mode` =  'reward' , status =  '0' ) coins.id ='".validstring($_request["coinid"])."' limit 0,1 

thanks lot...but have used following query , works fine >---->

select * , coins.id coinid coins  left join coin_owners on coin_owners.coin_id = coins.id  left join transfer_detail on transfer_detail.coin_id = coin_owners.coin_id , transfer_detail.transfer_to = coin_owners.current_owner , transfer_detail.transfer_from = substring_index( coin_owners.previous_owner,  ',',  '-1' ) , coin_owners.`ownership_mode` =  'transfer' left join rewards on rewards.`coin_ids` = coin_owners.coin_id  , coin_owners.`ownership_mode` =  'reward' , status =  '0'  coins.id ='".mysql_real_escape_string(trim($_request["coinid"]))."' limit 0,1  

thanks of help


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -