现在有4个表,表结构都很简单,
id name, 都是这样的结构,现在分别知道四个表中的name,想用一条语句把对应的4个id查出来就行,知道的说下,谢谢各位了SQL
id name, 都是这样的结构,现在分别知道四个表中的name,想用一条语句把对应的4个id查出来就行,知道的说下,谢谢各位了SQL
解决方案 »
- 求教数据迁移
- 急需Oracle10 patch 5391050 for Windows Server 2003 for 64-Bit Itanium2,谢谢!
- 细粒度访问原则
- 寻求linux下的C++ Oracle数据库开发资料或书籍
- 急!!!PROCEDURE 传值问题
- 这么一条SQL怎么写,郁闷了半天了,跪求答案!!
- 为什么自己创建的数据库在ome中登录的时候只能以normal权限登录,不能以sysdba登录呢?
- windows下如何连接linux下的oracle9i
- 用rownum的奇怪问题,求指导
- LOOP循环中如何控制COMMIT?
- oracle的问题
- 大表数据删除问题, 会delete 的都可以进来看看, 要多少分都可以!
union all
select id from tab2 where name='name2'
union all
select id from tab3 where name='name3'
union all
select id from tab4 where name='name4'
;
如果要去重的话,用union
不去重用union all
SELECT
(select name1 from table1 where id1 = '1') name1,
(select name2 from table2 where id2 = '2') name2,
(select name3 from table3 where id3 = '3') name3
from dual;
SELECT
(select id from table1) name1,
(select id from table2) name2,
(select id from table3) name3,
(select id from table4) name4
from dual;
(select id from table1) name1,
(select id from table2) name2,
(select id from table3) name3,
(select id from table4) name4
from dual;
应该这么写看好咯
select t.* from 表1 t where t.name in ('a','b','c','d')
union all
select t2.* from 表2 t2 where t2.name in ('a','b','c','d')
union all
select t3.* from 表3 t3 where t3.name in ('a','b','c','d')
union all
select t4.* from 表4 t4 where t4.name in ('a','b','c','d')上面查出的做为一张表 再group by 一下看看多少个重复 需要取哪些数据
select count(1) as 数量 ,t5.id , t5.name from
(
select t.* from 表1 t where t.name in ('a','b','c','d')
union all
select t2.* from 表2 t2 where t2.name in ('a','b','c','d')
union all
select t3.* from 表3 t3 where t3.name in ('a','b','c','d')
union all
select t4.* from 表4 t4 where t4.name in ('a','b','c','d')
) group by t5.id , t5.name