mysql multi join from same table give alias -
currently have following query
select * tabs join users d on tabs.`debit` = d.id join users c on tabs.`credit` = c.id as table contains 2 user objects names returned same so:
id | amount | type | id | username | avatar | id | username | avatar i need return following
id | amount | type | debit.id | debit.username | debit.avatar | credit.id | credit.username | credit.avatar or simmilar long column names users prefixed.
i think looking for. give try. (assuming id | amount | type belongs tabs table)
select t.id, t.amount, t.type, d.id 'debit.id', d.username 'debit.username', d.avatar 'debit.avatar', c.id 'credit.id', c.username 'credit.username', c.avatar 'credit.avatar', tabs t join users d on t.`debit` = d.id join users c on t.`credit` = c.id
Comments
Post a Comment