读书人

求按条件查询一个表解决办法

发布时间: 2012-02-24 16:30:38 作者: rapoo

求按条件查询一个表,急
tb1abc
123
231




tb2pghj
p1123
p2231

p3223
p4221


查tb2
tb2 的后面g,h,j分别要等于tb2的a,b,c字段


如这里要查出的结果应该是p1,p2

[解决办法]

SQL code
--改下select p from tb2 t where exists(select 1 from tb1 where g=t.a and h=t.b and j=t.c)
[解决办法]
SQL code
select b.* from tb1 a,tb2 b where a.g=b.g and a.h=b.h and a.j=b.j
[解决办法]
SQL code
select b.* from tb1 a,tb2 b where a.a=b.g and a.b=b.h and a.c=b.j
[解决办法]
SQL code
select b.* from tb1 a join tb2 b on a.g=b.g and a.h=b.h and a.j=b.j 

读书人网 >SQL Server

热点推荐