在sql server中连接表 [英] join table in sql server

查看:55
本文介绍了在sql server中连接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须加入下表:

加入这4张表

i have to join table below table:
join this 4 table

schd_mst:sch_id,date
schd_detail:sch_id,cust_id
cust_mst:cust_id,cust_name,city_id
city_mst:city_id,city_name



加入此3表:


join this 3 table:

tour_mst:date,cust_id
cust_mst:cust_id,cust_name,city_id
city_mst:city_id,city_name





我的2个查询如下:





my 2 query as below:

select sm.date,cm.cust_name,cim.city_name   from schd_detail inner join schd_mst sm on sm.Sch_id=sd.Sch_id inner join cust_mst cm on sd.cust_id =cm.cust_id inner join city_mst cim on cm.city_name=cim.city_id  where sm.date='2013-11-01'




select tm.date,cm.cust_name,cim.city_name from tour_mst tm inner join cust_mst cm on tm.cust_id =cm.cust_id inner join city_mst cim on cm.city_name=cim.city_id  where tm.date='2013-11-01'





i想要用上面的表加入单个查询



i want to join in single query with above tables

推荐答案





sel ect sm.date,cm.cust_name,cim.city_name来自schd_detail内部连接schd_mst sm on sm.Sch_id = sd.Sch_id内部连接cust_mst cm on sd.cust_id = cm.cust_id内部连接city_mst cim on cm.city_name = cim.city_id其中sm.date ='2013-11-01'



联盟所有



select tm.date ,cm.cust_name,来自tour_mst的cim.city_name tm内连接cust_mst cm on tm.cust_id = cm.cust_id inner join city_mst cim on cm.city_name = cim.city_id其中tm.date ='2013-11-01'





检查一次它将为你工​​作........
Hi,

select sm.date,cm.cust_name,cim.city_name from schd_detail inner join schd_mst sm on sm.Sch_id=sd.Sch_id inner join cust_mst cm on sd.cust_id =cm.cust_id inner join city_mst cim on cm.city_name=cim.city_id where sm.date='2013-11-01'

Union ALL

select tm.date,cm.cust_name,cim.city_name from tour_mst tm inner join cust_mst cm on tm.cust_id =cm.cust_id inner join city_mst cim on cm.city_name=cim.city_id where tm.date='2013-11-01'


Check this Once it will Work for u........


你做了没有说明你有什么问题...



看看这里: SQL连接的可视化表示 [ ^ ]

上面的文章可以帮助你理解如何加入的工作;)
You did not specify what kind of problem do you have...

Have a look here: Visual Representation of SQL Joins[^]
Above article should help you understand how JOIN's works ;)


SELECT sm.date, cm.cust_name, cim.city_name FROM
schd_detail AS sd INNER JOIN  schd_mst AS sm ON sm.sch_id=sd.sch_id
INNER JOIN cust_mst AS cm ON sd.cust_id =cm.cust_id
INNER JOIN city_mst AS cim ON cm.city_id=cim.city_id where sm.date='2013-11-01'
UNION
SELECT tm.date, cm.cust_name, cim.city_name FROM
tour_mst AS tm INNER JOIN cust_mst AS cm ON tm.cust_id =cm.cust_id
INNER JOIN  city_mst AS cim ON cm.city_id=cim.city_id where tm.date='2013-11-01'


这篇关于在sql server中连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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