首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-02-24 
求按条件查询一个表,急tb1abc123231tb2pghjp1123p2231p3223p4221查tb2tb2 的后面g,h,j分别要等于tb2的a,b,

求按条件查询一个表,急
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 

热点排行