当前位置: 代码迷 >> Sql Server >> 求按条件查询一个表,解决办法
  详细解决方案

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

热度:41   发布时间:2016-04-27 18:06:47.0
求按条件查询一个表,急
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
  相关解决方案