请教:怎样从表里找出两条相同的数据?

[复制链接]
查看11 | 回复9 | 2008-10-24 13:19:51 | 显示全部楼层 |阅读模式
请教:如果没有主键,怎样从表里找出几个字段完一样的数据呢?
比如:表:要在表table1里面找出A,B,C,D字段的值完全一样的数据,表没有主键。怎样做?谢谢!
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
我做了下面这样的测试可以但要建立一个与你要找的表结构相同的表存放相同数据
下面是我的测试不知道可不可以
create table test1(col_a varchar2(10),col_b varchar2(10),col_c varchar2(10),col_d varchar2(10),col_e varchar2(10),col_f varchar2(10));
SQL> select * from test1;
COL_ACOL_BCOL_CCOL_DCOL_ECOL_F
---------- ---------- ---------- ---------- ---------- ----------
a
b
c
d
e
f
b
c
d
e
f
a
c
d
e
f
a
b
d
e
f
a
b
c
e
f
a
b
c
d
f
a
b
c
d
e
a
b
c
d
e
f
create table test2 as select * from test1 where rownum str_rowid);
commit;
fetch test_rowid into str_rowid;
end loop;
end;
查看表test2
SQL> select * from test2;
COL_ACOL_BCOL_CCOL_DCOL_ECOL_F
---------- ---------- ---------- ---------- ---------- ----------
a
b
c
d
e
f
a
b
c
d
e
f
不知道这样可不可以
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
为什么表里要存储两条相同的数据?
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
select * from table1 t1,table2 t2
where t1.a = t2.a
and t1.b = t2.b
and t1.c = t2.c
and t1.d = t2.d
and t1.rowid!= t2.rowid
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
pub的搜索功能暂时不能用,可以google一下这个主题: zhouwf0726 取最新记录
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
学习一下 。
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
好久沒上了,就來回個貼吧。
select empno,ename from emp
where rowid != (select max(rowid) from emp d where emp.ename = d.ename and emp.empno = d.empno)
自己根據自己的需要修改吧。
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
[php]
select *
from test1 aa
where (col_a,col_b,col_c,col_d,col_e,col_f)
in (select col_a,col_b,col_c,col_d,col_e,col_f

from (select test1.*,count(1) ct

from test1

group by col_a,col_b,col_c,col_d,col_e,col_f having count(1)>1))
[/php]
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
having字句应该能实现.
回复

使用道具 举报

千问 | 2008-10-24 13:19:51 | 显示全部楼层
select * from table1 where rowid in (
select rowid from (
select rowid,row_number() over(partition by a,b,c,d order by a) rn from table1 ) where rn>1)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行