日期:2014-05-18  浏览次数:20335 次

求按条件查询一个表,急
tb1 a b c
1 2 3
2 3 1




tb2 p g h j
p1 1 2 3
p2 2 3 1

p3 2 2 3
p4 2 2 1


查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