首页 新闻 会员 周边

求一条 sql server 查询语句

0
悬赏园豆:30 [已解决问题] 解决于 2015-05-27 13:03

两张表,主外键关系:

A:  Id Code BId

      1     a      1

      2     b      1

      3     c      2

B:  Id Name

      1  hello

      2  world

 

现有一条数据:

Name 为 hello    

Code 为一张表

C: Code

       a

       b

怎么确定这条数据在数据库中已存在?

Eysa的主页 Eysa | 初学一级 | 园豆:62
提问于:2015-04-29 09:20
< >
分享
最佳答案
0

exists(select * from A inner join B on A.Bid=B.Id inner join C on A.Code=C.Code where B.Name='hello')

收获园豆:30
519740105 | 大侠五级 |园豆:5810 | 2015-04-29 09:39
其他回答(1)
0

select count(*)  from B  where B.Name='hello' and  exists(select 1 from A where B.Id=A.BId  and  (A.Code='a' or A.Code='b'))  

雨若亭轩 | 园豆:206 (菜鸟二级) | 2015-04-29 09:26

谢谢,如果Code是在一张表里,比如C表,该怎么写?

支持(0) 反对(0) Eysa | 园豆:62 (初学一级) | 2015-04-29 09:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册