示例
帐务表:
id | name
1 | Checking
2 | Visa
交易表:
date | description | amount | from_id | to_id
10-8 | payment | $100 | 1 | 2
问题:
如何查询事务表并获取from_id和to_id列的名称,这两个列都引用了Accounts表中的id列?
使用上面的例子,我试图返回:
date | description | amount | from | to
10-8 | payment | $100 | Checking | Visa
发布于 2021-10-08 15:17:01
你必须参加两次:
select t.date, t.description, t.amount, a_from.name fromname, a_to.name toName
from transactions t
join accounts a_to on t.to_id = a_to.id
join accounts a_from on t.from_id = a_from.id
https://stackoverflow.com/questions/69498133
复制相似问题