我想要实现以下查询,请问sql语句该怎么写:
设有表t1,t2
t1有字段A,B,C,D,E,F
t2有字段A,B,C,M,N
我想要从表t2中查询记录,以使(A,B,C)满足条件:select A,B,C from t1 where D='d1' and E='e1',即这个T-SQL语句查找出的(A,B,C)作为条件来查询t2中的记录。
请教怎样写sql查询语句?
设有表t1,t2
t1有字段A,B,C,D,E,F
t2有字段A,B,C,M,N
我想要从表t2中查询记录,以使(A,B,C)满足条件:select A,B,C from t1 where D='d1' and E='e1',即这个T-SQL语句查找出的(A,B,C)作为条件来查询t2中的记录。
请教怎样写sql查询语句?
where exists (select 1 from t1 where D='d1' and E='e1'
and t2.A=t1.A and t2.B=t1.B and t2.C=t1.C)
WHERE a.A=b.A AND a.B=b.B and a.C=b.C and a.D='d1' and a.E='e1'
SELECT b.* FROM t1 a,t2 b
WHERE a.A=b.A AND a.B=b.B and a.C=b.C and a.D='d1' and a.E='e1'
WHERE a.A=b.A AND a.B=b.B and a.C=b.C and a.D='d1' and a.E='e1'
WHERE a.D='d1' and a.E='e1'
select b.* from t1 a join t2 b on a.A=B.A and a.B=b.B and a.C=b.C
WHERE a.D='d1' and a.E='e1'
select A,B,C,M,N from t2 a
where exists(
select 1 from t1
where A=a.A and B=a.B and C=a.C
and D='d1' and E='e1'
)
where exists (select 1 from t1 where D='d1' and E='e1'
and t2.A=t1.A and t2.B=t1.B and t2.C=t1.C)