with t1 as(
select '1' id ,'test1' name, '1' codes from dual
union all
select '1' id ,'test1' name, '11' codes from dual
union all
select '2' id ,'test2' name, '2' codes from dual
union all
select '2' id ,'test2' name, '22' codes from dual
union all
select '3' id ,'test3' name, '3' codes from dual
),
t2 as(
select '1' id ,'test1' name, '11' codes from dual
union all
select '1' id ,'test1' name, '111' codes from dual
union all
select '2' id ,'test2' name, '2' codes from dual
)有表t1,t2,如上;
现在要查询出,t1.id=t2.id and t1.name= t2.name 且t1中codes在t2中不存在的记录;
上面的结果应该是这样的:
id name codes
1 test1 1
2 test2 22
解决方案 »
- orcale spool 问题
- ---------------月份跨年度查询数据------------【100分求助】
- 请问各位高手如何获得longrow字段的长度,判断是否为空!!!在线线等待!急!
- 各位大哥大姐好,求救BAT实现自动恢复的脚本.
- 关于裸设备上的ORACLE问题,十分不解
- 请教:Io 异常: Software caused connection abort: socket write error ??
- 问一个SQL语句的写法
- 字段数目限制?急!!!
- 100分求助Oracle简单问题~~
- oracle 中 clob 字段的问题
- PL/sql 里对日期字段2012-2-3 这样的怎样查询出只显示年份的?因为有好多不同年份的
- oracle储存过程问题。需要传入一个id的串。id在数据库内定义为number。那么运行这个存储过程时怎么定义这个id串?
AND codes NOT IN (SELECT DISTINCT codes FROM t2)
或者
SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE id=t1.id AND NAME=t1.NAME )
MINUS
SELECT * FROM t2
select * from t1
where not exists (select 1 from t2
where t1.id=t2.id and t1.name= t2.name and t1.codes=t2.codes)
and exists(select 1 from t2
where t1.id=t2.id and t1.name= t2.name);
需要将已经存在于t2表中id+name,在t1表中新增的codes的记录查询出来;我不大清楚,在主贴中,我那个说法合理不