有多个表结构相同的表,期望得到的结果:多个表的查询跟一个表的查询类似,一个结果集
如下:
create table a(
id int primary key,
code nverchar2(6),
value nverchar2(50)
)
create table b(
id int primary key,
code nverchar2(6),
value nverchar2(50)
)
其中表a和表b中的id有肯能相同,但不同表的code不同
期望结果:查询出来的值好比是一个表查出来的效果
如下:
create table a(
id int primary key,
code nverchar2(6),
value nverchar2(50)
)
create table b(
id int primary key,
code nverchar2(6),
value nverchar2(50)
)
其中表a和表b中的id有肯能相同,但不同表的code不同
期望结果:查询出来的值好比是一个表查出来的效果
解决方案 »
- Oracle 10g中的dbconsole服务无法启动
- 一个ubuntu oracle数据库调用sqlplus执行.sql脚本的问题
- 帮帮忙.Oracle9,Oracle10执行通过的语句Oracle8执行不通过?
- 一对多的两表中,只想得到多那一方的一条记录,该怎么写PL/SQL?
- 用 imp 把nvh_struct.dmp导入数据库后,怎样查看是否导入成功??
- 如何实现SQL Server数据库中的某张表,定时导入Oracle数据库中?
- 来者有分,可以像Access,SQLserver那样自动插入时间吗?
- 能否给点有关用JOB定期执行ANASYLE的源码,还希望各位指教呀。
- 请问那位朋友有严蔚敏的那本数据结构的C语言版的pdf格式的清晰文档,能给我一份吗,万分感激!
- win7安装oracle10g直接报错,求大神进来看看这是怎么回事啊!!!
- Oracle和Java程序
- 求数据库中的一个正则表达式
select id,code,value from a
union all select id,code,value from b;
不好意思,我弄错了,是我以前查的时候没有注意报错的信息,union all可以。以前是因为两张表结构不太一样。麻烦再问下,关于oracle中的临时表,如果用临时表处理上面的2张表,有什么好处和坏处?
怎么对查询结果字段作为条件进行查询问题补充如下:
create table dict(
id int primary key,
codegroup nverchar2(6),
code nverchar2(6),
value nverchar2(100)
)
insert into dict values(1,'01','','a');
insert into dict values(2,'01','011','b');
insert into dict values(3,'01','012','c');
insert into dict values(4,'01','013','d');
create newTable(
id int primary key ,
code nverchar2(6)
)
insert into newTable values(1,'012');
insert into newTable values(2,'013');
查询newTable表,要求查询结果中包含dict表中codegroup=01 code=null的值------------下面是我实现的sql不过感觉有点怪,求高人给指点--------------------------------
select id,code,
(
case when 1=1 then (select value from dict where id=(select id from dict where code is null and codegroup =(select max(codegroup) from dict where code = newTable.code)) end)
)
from newTable
这个是啥意思?因为在newTable中只跟dict表中的code有对应关系,而现在需要查询newTable表和dict表中的codegroup的对应关系, 也就是在查询出netTable表中的code值的时候需要再次在dict表中进行一次查询得到codegroup的值---
纠正一个自己的错误,数据类型nvarchar2写错了,写成nverchar2了