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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -