我在数据库中有三个表:makers
,parts
,transfers
。
Makers
是
makerid,stampname
Parts
是
categories,name
variations
是
id, provider, recipient, part
Provider
是指向makers/makerid
的指针,因此recipients
。
我需要查询,以便我的结果显示友好名称与编码/简化数据库ID。
我尝试了几个连接,但我的查询:
select makers.stampname as giver, makers.stampname as takers
from makers
left join variations prov on prov.provider=makers.makerid
left join variations recp on recp.recipient=makers.makerid limit 5;
在两列中生成相同的名称。如果provider
为makerid
24且recipient
为makerid
10,我如何获取查询以回复来自{{1}的重合stampname
db?
答案 0 :(得分:0)
抱歉,看起来需要更好地理解别名。这非常有效:
select variations.date,provider.stampname as provname ,
recipient.stampname as recipname,
parts.name from variations
left outer join
makers provider on variations.provider = provider.makerid
left outer join
makers recipient on variations.recipient = recipient.makerid
left join categories parts on variations.part = parts.catid
where variations.provider = "20"
and
variations.date="1944";