两张表,主外键关系:
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
怎么确定这条数据在数据库中已存在?
exists(select * from A inner join B on A.Bid=B.Id inner join C on A.Code=C.Code where B.Name='hello')
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'))
谢谢,如果Code是在一张表里,比如C表,该怎么写?