如何在sql server 2008中连接两个表 [英] How to join two tables in sql server 2008

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

问题描述

其实我有两张桌子(Tabel1,Tabel2)



表11记录: -



 ID名称
1 Sri
2 Giri





Tabel2记录: -



 ID状态
1 A
2







现在我想要以下声明的记录



select *来自tabel1,tabel2,其中tabel1.ID = Tabel2.ID和Tabel2.Status ='A'和name ='Giri'输出应如下所示。



< pre lang =vb> ID名称状态
2 Giri Null

解决方案

你可以试试下面的代码...





 选择 t1.ID,t1.NAME,t2.STATUS  fr om 表1 t1 
left join 表2 t2 on t1.ID = t2.ID t2.STATUS = ' < span class =code-string> A'
其中 t1.ID = 2


按照它可能对你有用的链接..





SQL连接的可视化表示 [ ^ ]


Actually i am having two tables (Tabel1,Tabel2)

Table11 Records:-

ID   Name 
1    Sri
2    Giri



Tabel2 Records:-

ID  Status
1    A
2    I




Now i want the record like for below statement

select * from tabel1,tabel2 where tabel1.ID=Tabel2.ID and Tabel2.Status='A' and name='Giri' Output should be like below.

ID  Name  Status
2   Giri  Null

解决方案

You can try the below code...


Select t1.ID,t1.NAME,t2.STATUS from Table1 t1
left join Table2 t2 on t1.ID=t2.ID and t2.STATUS='A'
where t1.ID=2


Follow the link it might help to you..


Visual Representation of SQL Joins[^]


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

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