SQL语句中,查询一个结果,满足表1的A条件,满足表2的B条件,怎么写?

select *from 表1 where 条件='1'
select *from 表2 where 条件>0

用左连接怎么写表达式、?????

1.创建测试表,

创建表test_col_1(id号,varvarchar2(200));

创建表test_col_2(id号,varvarchar2(200));

2.插入测试数据,

insertintotest_col_1

选择level*8, 'var'||*8 from dual connect by level <= 20;

insertintotest_col_2

选择level,‘var’||level from dual connect by level <= 100;

3.查询表A和表B中的相关记录,

Select*

fromtest_col_2b

Whereexists(select1fromtest_col_1awhereb。id=a.id)

4.查询表A中的所有数据和A、B中的相关数据,

Select*

fromtest_col_1a

unionall

Select*

fromtest_col_2b

Whereexists(select1fromtest_col_1awhereb。id=a.id)

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-07-04
select * from 表1,表2 where A条件 AND B条件 AND 表1.a=表2.b
这个,主要你的表1和表2 之间要有关系啊,没关系的话不好写。
第2个回答  推荐于2018-04-11
假如表1,表2分别为table1,table2,关联字段是id,那么
select t1.*, t2.* from table1 t1, table2 t2 where t1.id = t2.id and t1.字段 = A条件 and t2.字段 = B条件

左连接就是left join啊
select * from table1 t1 left join table2 t2 on t1.id = t2.id where t1.字段 = A条件 and t2.字段 = B条件追问

t1 t2 是什么意思??

追答

就是表1,table1,和表2,table2的别名啊,当你的表的名字很长时,用别名方便一点啊!我取得别名就是t1,t2啊,你不会连这个也不知道吧!

本回答被提问者和网友采纳
第3个回答  2011-07-04
问:表1,表2是通过那个字段关联。
相似回答