我在数据库中有三个表: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,我该如何从stampname
数据库中获取查询以响应一致的makers
? 最佳答案
抱歉,看起来这是需要更好地了解别名的问题。这完美地工作:
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";
关于mysql - 连接多个mysql表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47745505/