如何用SQL语句查询两张表中的相同字段数据

如何用SQL语句查询两张表中的相同字段数据

问题描述:

在ORACL数据库中表table1有字段codeid和cedename两个字段,表table2中也有codeid和codename字段,如何用一条SQL语句将这两张表的两个字段查询出来

select codeid,cedename from table1
union all
select codeid,cedename from table2

会把2张表的数据汇总在一起

select * from table1 inner join table2 on table1.codeid=table2.codeid

查询 这两张表的数据
select t1.codeid ,t1.cedename from table1 t1
union all
select t2.codeid ,t2.cedename from table1 t2
查询 这两张表的数据(去掉重复数据)
select t1.codeid ,t1.cedename from table1 t1
union
select t2.codeid ,t2.cedename from table1 t2

说说你的要实现的目的,应该不是简单的把两个表的内容全部查询吧!两者表字段完全一样的字段之间有什么联系。

没什么特殊要求吗?要没有的话上面的回答都能满足

select t1.codeid ,t1.cedename t2.cedename,t2.codeid ,tafrom table1 t1, table2 t2

没看懂,lz到底想干什么