在同一个表中为多个列执行内部联接 [英] Performing Inner Join for Multiple Columns in the Same Table

查看:60
本文介绍了在同一个表中为多个列执行内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i我必须在第一个city_master和第二个交易中表示



City_Master



id城市

1 Nagpur

2孟买

3 Pune



Transcation



id Supplier_name产品数量城市Alt_City

1 Nikhil Iron 100 1 2

2 Amit Copper 100 1 3

3 Rohit Steel 100 3 1



i想要查询输出如下



1 Nikhil Iron 100 Nagpur Mumbai

2 Amit Copper 100 Nagpur Pune

3 Rohit Steel 100 Pune Nagpur

解决方案

它会给你预期的输出



选择所有列

 选择 * 来自 交易 t 
加入 City_Master cm on t.Alt_City = cm.id





对于选定的列



 选择 t.Supplier_Name,t.Product,t.Qty,cm.City 来自 交易 t 
加入 City_Master cm < span class =code-keyword> on t.Alt_City = cm.id





有关加入的更多信息,请访问此链接


hi friend,



试试这个...





 选择 T0.id,T0.Supplier_name,T0.Product,T0.Qty,(选择 A.City  City_Master A.id =的code-keyword> T0.City) as  '  City' ,(选择 A.City 来自 City_Master A.id = T0.Alt_City) as  '  Alt_City'  Transcation T0 









快乐编码:)


hi
i am having to table 1st one city_master and 2nd Transaction

City_Master

id City
1 Nagpur
2 Mumbai
3 Pune

Transcation

id Supplier_name Product Qty City Alt_City
1 Nikhil Iron 100 1 2
2 Amit Copper 100 1 3
3 Rohit Steel 100 3 1

i want query output like below

1 Nikhil Iron 100 Nagpur Mumbai
2 Amit Copper 100 Nagpur Pune
3 Rohit Steel 100 Pune Nagpur

解决方案

it will give your Expected output

To select All Columns

Select * from transaction t
join City_Master cm on t.Alt_City=cm.id



For selected Columns

Select t.Supplier_Name,t.Product,t.Qty,cm.City from transaction t
join City_Master cm on t.Alt_City=cm.id



for more info about join please visit this link


hi friend,

Try This...


Select T0.id, T0.Supplier_name, T0.Product, T0.Qty ,(select A.City from City_Master A.id=T0.City) as 'City', (select A.City from City_Master A.id=T0.Alt_City) as 'Alt_City' from Transcation T0





Happy Coding :)


这篇关于在同一个表中为多个列执行内部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆