SQL语句如何用一个表的数据从另外一个表中找出相同的项出来?
1、创建测试表,
create table test_tbl_1(id varchar2(20),name varchar2(20));
create table test_tbl_2(name varchar2(20));
2、插入测试数据;
insert into test_tbl_1 values (1,'张三');
insert into test_tbl_1 values (2,'王二');
insert into test_tbl_1 values (3,'李四');
insert into test_tbl_1 values (4,'赵五');
insert into test_tbl_2 values ('张三');
insert into test_tbl_2 values ('王五');
insert into test_tbl_2 values ('李四');
insert into test_tbl_2 values ('马六');
commit;
3、查询test_tbl_1表中全量数据;select t.*, rowid from test_tbl_1 t;
4、编写语句,从表2的姓名列,找到跟表1姓名列相同的项;
select * from test_tbl_1 where name in (select name from test_tbl_2);
2014-03-14
from table1 a
where a. 姓名 in(select distinct 姓名 from table2)
2014-03-13
select * from table1 t,table2 t2 where t.name=t2.name
广告 您可能关注的内容 |