SQL语句如何用一个表的数据从另外一个表中找出相同的项出来?

现有表1、表2
我想从表2的姓名列,找到跟表1姓名列相同的项,该怎么写语句?谢谢

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);

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-14
使用以下语句试试:select * from 表1 left join 表2 where 表1.字段1=表2.字段1
第2个回答  推荐于2018-02-27
select a.*
from table1 a

where a. 姓名 in(select distinct 姓名 from table2)本回答被提问者和网友采纳
第3个回答  2014-03-13
查询结果是什么,连接查询不就行了
select * from table1 t,table2 t2 where t.name=t2.name
第4个回答  2014-03-13
select * from 表2 a inner join 表1 b on a.name= b.name
相似回答