Duplicate rows in 5 table
I have five tables(A,B,C,D,E), and I am trying to check for duplicate rows in all the tables, I tried using inner join, but the first three join did not return any table. is there another way.the tables only have two columns , the email(different values)
and authour (which is the same person in the table)
when i tried
select * from TABLE A
INNER JOIN TABLE B
ON TABLEA. EMAIL = TABLEB.EMAIL
INNER JOIN TABLEC
ON TABLEA.EMAIL=TABLEC.EMAIL
it came back with no result, the other way I am thinking is to unioun all all the tables and try to use count and group by ,but this will only show me the duplicates and not the authours
please any other way
it came back with no result, the other way I am thinking is to unioun all all the tables and try to use count and group by (but I could not insert my result in a new table)
please any other way
I dont understand your point here...Are you trying the below?
Create Table T1(name varchar(50),Email Varchar(50))
Insert into T1 Values('SQL','[email protected]'),('.NET','[email protected]')
Create Table T2(name varchar(50),Email Varchar(50))
Insert into T2 Values('Server','[email protected]'),('BizTalk','[email protected]')
Create Table T3(name varchar(50),Email Varchar(50))
Insert into T2 Values('Sql','[email protected]'),('server','[email protected]')
;With cte as
(Select * From T1
Union All
Select * From T2
Union All
Select * From T3)
Select name,email, count(1) From cte Group by name , email having count(1)>1
Drop table T1,T2,T3
I was able to insert the union product in a table, and i used this
SELECT EMAIL,AUTHOR,COUNT(EMAIL) AS AMOUNT FROM ALLEMAIL
GROUP BY AUTHOR,EMAIL
ORDER BY AMOUNT DESC, email desc
but its showing the email and the count but its appearing like the duplicate is only associated with one authour
Similar Messages
-
How to eliminate the duplicate rows in the table
How can we eliminate the duplicate rows in the table. Is it possible to write a single query or should we write a pl/sql block to do it
Scope works outwards.
SQL> DECLARE
2 n NUMBER;
3 BEGIN
4 n := 0;
5 DECLARE
6 n number;
7 BEGIN
8 n := 2;
9 dbms_output.put_line(n);
10 END;
11 END;
12 /
2
PL/SQL procedure successfully completed.
SQL> DECLARE
2 n NUMBER;
3 BEGIN
4 n := 0;
5 DECLARE
6 x number;
7 BEGIN
8 dbms_output.put_line(n);
9 n := 2;
10 dbms_output.put_line(n);
11 END;
12 END;
13 /
0
2
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 n NUMBER;
3 BEGIN
4 n := 0;
5 DECLARE
6 x number;
7 BEGIN
8 dbms_output.put_line(n);
9 x := 2;
10 END;
11 dbms_output.put_line(x);
12 EXCEPTION
13 WHEN others THEN dbms_output.put_line('oh no!');
14* END;
15 /
dbms_output.put_line(x);
ERROR at line 11:
ORA-06550: line 11, column 27:
PLS-00201: identifier 'X' must be declared
ORA-06550: line 11, column 6:
PL/SQL: Statement ignored
SQL> Cheers, APC -
Need to remove duplicate rows from a table
Hi Gurus ,
I am using oracle 11.2.0.3 .
SQL> desc osstage.S_EVT_ACT_X;
Name Null? Type
ROW_ID NOT NULL VARCHAR2(15 CHAR)
LAST_UPD NOT NULL DATE
PAR_ROW_ID NOT NULL VARCHAR2(15 CHAR)
ATTRIB_17 NUMBER(22,7)
ATTRIB_26 DATE
ATTRIB_02 VARCHAR2(100 CHAR)
PROCESS_TIMESTAMP TIMESTAMP(6);
now when i give the below command it gives the error as someone has disabled the constraint accidently .
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1;
Error starting at line 3 in command:
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1
Error report:
SQL Error: ORA-02437: cannot validate (OSSTAGE.S_EVT_ACT_X_P1) - primary key violated
02437. 00000 - "cannot validate (%s.%s) - primary key violated"
*Cause: attempted to validate a primary key with duplicate values or null
values.
*Action: remove the duplicates and null values before enabling a primary
key.
Can you please guide me with this issue .Please refer
Script: Deleting Duplicate Rows from a Table (Doc ID 31413.1)
How to Find or Delete Duplicate Rows in a Table (Doc ID 1004425.6) -
SQL Server 2014 - Delete duplicate rows in a table except one
Hi all,
I have a table that contains duplicate rows. Using grouping I can easily identify those rows.
As of now, I count the grouped records and copy one of the group in a temporary table together with its count of elements. Than I loop over this table and delete N - 1 rows of each group from the original table. Unfortunately this is done with two cursors
and WHILE loops.
Is anybody out there who could give some hints how to handle deletion of duplicated rows leaving one in place using pure SQL? I tried a full delete of all elements of a group and then an INSERT of one row to recreate a row again. But this is not
very elegant and close to using cursors.
Regards UweHi all,
based on input below from Uri, I have developed a little more general solution for removal of duplicates. I did that, because I'm sure that for many beginners in SQL it is easier specialize a proposal by removing parts of it than adding new functionality.
Here is my code.
-- Remove duplicates from a table and document the deleted rows
DECLARE @MyTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
DECLARE @OutTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
INSERT INTO @MyTable VALUES
(1, 10, 100, 7),
(2, 20, 200, 2),
(2, 20, 200, 1),
(3, 30, 300, 3),
(1, 10, 200, 4),
(1, 10, 100, 5),
(1, 10, 100, 6);
WITH cte (RN, Col1, Col2, Col3, Col4)
AS (SELECT ROW_NUMBER() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY (SELECT 0)) AS RN, Col1, Col2, Col3, Col4
FROM @MyTable)
DELETE FROM cte
OUTPUT DELETED.Col1, DELETED.Col2, DELETED.Col3, DELETED.Col4
INTO @OutTable (Col1, Col2, Col3, Col4)
WHERE RN > 1;
SELECT * FROM @OutTable;
And this is the result:
The MS 139444 article Satish mentioned is focussed on duplicate PKs removal. Thanks for the hint.
Thanks to you all for your rapid response.
Regards Uwe -
First attempt to remove duplicate rows from a table...
I have seen many people asking for a way to remove duplicate rows from data. I made up a fairly simple script. It adds a column to the table with the cell selected in it, and adds the concatenation of the data to the left into that new column. then it reads that into a list, and walks through that list to find any that are listed twice. Any that are it marks for DELETE.
It then walks through to find each one marked for delete and removes them (you must go from bottom to top to do this, otherwise your row markings for delete don't match up to the original rows anymore). Last is to delete the column we added.
tell application "Numbers"
activate
tell document 1
-- DETERMINE THE CURRENT SHEET
set currentsheetindex to 0
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of (tables whose selection range is not missing value)
end tell
if x is not 0 then
set the currentsheetindex to i
exit repeat
end if
end repeat
if the currentsheetindex is 0 then error "No sheet has a selected table."
-- GET THE TABLE WITH CELLS
tell sheet currentsheetindex
set the current_table to the first table whose selection range is not missing value
end tell
end tell
log current_table
tell current_table
set list1 to {}
add column after column (count of columns)
set z to (count of columns)
repeat with j from 1 to (count of rows)
set m to ""
repeat with i from 1 to (z - 1)
set m to m & value of (cell i of row j)
end repeat
set value of cell z of row j to m
end repeat
set MyRange to value of every cell of column z
repeat with i from 1 to (count of items of MyRange)
set n to item i of MyRange
if n is in list1 then
set end of list1 to "Delete"
else
set end of list1 to n
end if
end repeat
repeat with i from (count of items of list1) to 1 by -1
set n to item i of list1
if n = "Delete" then remove row i
end repeat
remove column z
end tell
end tell
Let me know how it works for y'all, it worked good on my machine, but I know localization is causing errors sometimes when I post things.
Thanks,
Jason
Message was edited by: jaxjasonHi jason
I hope that with the added comments it will be clear.
Ask if something is always opaque.
set {current_Range, current_table, current_Sheet, current_Doc} to my getSelection()
tell application "Numbers09"
tell document current_Doc to tell sheet current_Sheet to tell table current_table
set list1 to {}
add column after column (count of columns)
set z to (count of columns)
repeat with j from 1 to (count of rows)
set m to ""
tell row j
repeat with i from 1 to (z - 1)
set m to m & value of cell i
end repeat
set value of cell z to m
end tell
end repeat
set theRange to value of every cell of column z
repeat with i from (count of items of theRange) to 1 by -1
(* As I scan the table backwards (starting from the bottom row),
I may remove a row immediately when I discover that it is a duplicate *)
set n to item i of theRange
if n is in list1 then
remove row i
else
set end of list1 to n
end if
end repeat
remove column z
end tell
end tell
--=====
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers09" to tell document 1
set theSheet to ""
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
(* Open a trap to catch the selection range.
The structure of this item
«class
can't be coerced as text.
So, when the instruction (selection range of table y) as text
receive 'missing value' it behaves correctly and the lup continue.
But, when it receive THE true selection range, it generates an error
whose message is errMsg and number is errNum.
We grab them just after the on error instruction *)
try
(selection range of table y) as text
on error errMsg number errNum (*
As we reached THE selection range, we are here.
We grab the errMsg here. In French it looks like:
"Impossible de transformer «class
The handler cuts it in pieces using quots as delimiters.
item 1 (_) "Impossible de transformer «class » "
item 2 (theRange) "A2:M25"
item 3 (_) " of «class NmTb» "
item 4 (theTable) "Tableau 1"
item 5 (_) " of «class NmSh» "
item 6 (theSheet) "Feuille 1"
item 7 (_) " of document "
item 8 (theDoc) "Sans titre"
item 9 ( I drop it ) " of application "
item 10 ( I drop it ) "Numbers"
item 11 (I drop it ) " en type string."
I grab these items in the list
{_, theRange, _, theTable, _, theSheet, _, theDoc}
Yes, underscore is a valid name of variable.
I often uses it when I want to drop something.
An alternate way would be to code:
set ll to my decoupe(errMsg, quote)
set theRange to item 2 of ll
set theTable to item 4 of ll
set theSheet to item 8 of ll
set theDoc to item 10 of ll
it works exactly the same but it's not so elegant.
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
exit repeat (*
as we grabbed the interesting datas, we exit the lup indexed by y.*)
end try
end repeat -- y
if theSheet > "" then exit repeat (*
If we are here after grabbing the datas, theSheet is not "" so we exit the lup indexed by i *)
end if
end tell -- sheet
end repeat -- i
(* We may arrive here with two kinds of results.
if we grabbed a selection, theSheet is something like "Feuille 1"
if we didn't grabbed a selection, theSheet is the "" defined on entry
and we generate an error which is not trapped so it stops the program *)
if theSheet = "" then error "No sheet has a selected table."
end tell -- document
(* Now, we send to the caller the interesting datas :
theRange "A2:M25"
theTable "Tableau 1"
theSheet "Feuille 1"
theDoc "Sans titre" *)
return {theRange, theTable, theSheet, theDoc}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d (*
Cut the text t in pieces using d as delimiter *)
set l to text items of t
set AppleScript's text item delimiters to "" (*
Resets the delimiters to the standard value. *)
(* Send the list to the caller *)
return l
end decoupe
--=====
Have fun
And if it's not clear enough, you may ask for more explanations.
Yvan KOENIG (from FRANCE mardi 27 janvier 2009 21:49:19) -
Urgent - Deletion of duplicate rows in a table - Help me
Hi friends,
Here is my purchase_order_line table desc,
SQL> desc purchase_order_line;
Name Null? Type
PURCHASE_ORDER_LINE_ID NOT NULL NUMBER
DESTINATION_ID NOT NULL NUMBER
PURCHASE_ORDER_ID NOT NULL NUMBER
LINE_NO NOT NULL NUMBER
PART_NO VARCHAR2(10)
PART_DESC NOT NULL VARCHAR2(100)
ORDER_QTY NOT NULL NUMBER
ORDER_DATE NOT NULL DATE
DUE_DATE DATE
VERSION_NO NOT NULL NUMBER
VERSION_DATE NOT NULL DATE
purchase_order_line_id is a primary key.
If you ignore the primary key column temporarily,
for the rest of 2 to 11 columns, i have a duplicate data in this table.
I want to clear out all duplicates.
Suppose if I have 3 similar rows(exclude primarykey), then delete first two rows and leave the last one.
OR delete last two rows and leave the first one.
What is the best solution for this ?
thanks for help.
Sridharhere is some example that might be of help.
SQL> select case_number, case_status_desc status, case_ownr owner,
2 case_yr year, doc_id
3 from wrt_case
4 order by doc_id;
CASE_NUMBER STATUS OWNER YEAR DOC_ID
2006-786 ACTIVE E 2006 22072734
2006-786 ACTIVE E 2006 22072734
2006-786 ACTIVE E 2006 22081673
2006-786 ACTIVE E 2006 22081673
2006-786 ACTIVE E 2006 22143005
2006-786 ACTIVE E 2006 22143005
2006-786 ACTIVE E 2006 22243094
2006-786 ACTIVE E 2006 22243094
8 rows selected.
SQL> Select case_number, case_status_desc status, case_ownr owner,
2 case_yr year, doc_id, rowid,
3 row_number() over (partition by doc_id order by doc_id) as rn
4 From wrt_case;
CASE_NUMBER STATUS OWNER YEAR DOC_ID ROWID RN
2006-786 ACTIVE E 2006 22072734 AAD8bTAAJAAAJ4nAAA 1
2006-786 ACTIVE E 2006 22072734 AAD8bTAAJAAAJ4nAAC 2
2006-786 ACTIVE E 2006 22081673 AAD8bTAAJAAAJ4nAAB 1
2006-786 ACTIVE E 2006 22081673 AAD8bTAAJAAAJ4nAAD 2
2006-786 ACTIVE E 2006 22143005 AAD8bTAAJAAAJ4nAAE 1
2006-786 ACTIVE E 2006 22143005 AAD8bTAAJAAAJ4nAAF 2
2006-786 ACTIVE E 2006 22243094 AAD8bTAAJAAAJ4nAAG 1
2006-786 ACTIVE E 2006 22243094 AAD8bTAAJAAAJ4nAAH 2
8 rows selected.
SQL> Delete From wrt_case
2 Where rowid in (Select t.rid
3 From (Select case_number, case_status_desc status, case_ownr owner,
4 case_yr year, doc_id, rowid as rid,
5 row_number() over (partition by doc_id order by doc_id) as rn
6 From wrt_case) t
7 Where t.rn > 1);
4 rows deleted.
SQL> select case_number, case_status_desc status, case_ownr owner,
2 case_yr year, doc_id, rowid
3 from wrt_case
4 order by doc_id;
CASE_NUMBER STATUS OWNER YEAR DOC_ID ROWID
2006-786 ACTIVE E 2006 22072734 AAD8bTAAJAAAJ4nAAA
2006-786 ACTIVE E 2006 22081673 AAD8bTAAJAAAJ4nAAB
2006-786 ACTIVE E 2006 22143005 AAD8bTAAJAAAJ4nAAE
2006-786 ACTIVE E 2006 22243094 AAD8bTAAJAAAJ4nAAG
SQL> -
How to delete duplicate rows in a table
hai,
i have a table which consists of hunderds of records and contains duplicate records also. how can i delete duplicate records.
thanks
raviThis maybe a litle bit fast for deletion:-
delete from emp where rowid in (
2 SELECT rowid FROM emp
3 group by rowid,empno,ename,job
4 minus
5 SELECT min(rowid) FROM emp
6 group by empno,ename,job); -
Noob question about trying to duplicate rows in a table
Simplification of problem is I've got a table with user_id, name, year where user_id is pk. I would like to take all the rows that match year=2008 and insert them into the same table, but start the user_id at a certain number and set year=2009.
I know this doesn't work, but it's what I want to do in noob-code:
INSERT into TABLE (
user_id, name, year
) VALUES (
SELECT user_id_seq.nextval after starting at 3500, name, 2009 from same table doing insert to where year = 2008
I've contemplated using a temporary table, I've also seen mention of cursors, but don't quite understand what they are. I'm really, really new to Oracle and SQL in general, but am familiar with programming and shell scripts. I know more in depth searching might land me what I want, but I think my search syntax would be just as weak as my knowledge of the material. I'm just thinking this is something so basic and easy that my searches aren't using the right terms to catch a hit.Hi,
Welcome to the forum!
You can INSERT all the results of a query by substituting the query where you otherwise would have "VALUES (list)".
For example:
INSERT into TABLE_X
(user_id, name, year)
SELECT user_id_seq.NEXTVAL, name, 2009
FROM table_x
WHERE year = 2008;This assumes that the sequence user_id_seq exists and is ready to issue the correct value. (It's unclear if that's part of the problem.)
Temporary tables and cursors (which are a way of getting query results in PL/SQL) are only useful for inserting in rare situations, where you have to do very odd, convoluted things. Think (at least) twice about how to do what you need to in SQL, and if you can't think of a way, then ask.
Yes, basic things often are hard to search for, especially if you don't know the right terms.
There are several good teach-yourself SQL books that explain this kind of thing. Getting one would be a good investment.
[All the Oracle manuals|http://www.oracle.com/pls/db111/portal.all_books] are on line. There's an example of this in the SQL Reference manual, under THE INSERT command.
Edited by: Frank Kulash on Nov 26, 2008 12:59 PM
Clarified usefulness of cursors. They have a lot of good, common functions, but helping with INSERTs is not one of them. -
Duplicate rows in Detail Table - Master Detail Relationship
Hi,
I have developed the Page it has following components. (Jdeveloper 10g - R12)
1) Query RN
It has around 11 parameters, 5 parameters have LOV attached, 2 are mandatory parameters.
Auto Customization criteria. we don't criteria map defined , where clause is build based on parameters and vo.executeQuery gets called on Go button click.
2) Sales Order Table RN (Master)
3) Sales Order Line Table RN (Detail)
View link is created to maintain the master detail relationship and detail region is attached to AM using view link under master region.
Page flow works in this way, when user enter the parameters in search region and click on Go button, Sales Order table RN (master) gets populated.
It has radio button when user click it fires PPR event .
Process form request gets called and master row gets set (Same code as per developer guide) and Sales Order Line table RN (detail).
Problem is once detail region gets populate and when user change any parameter which has LOV attached somehow same rows gets added to detail region which is weird because we have not clicked on GO button and radio button on header region is also not touched but detail region is populated somehow.
Please help
Thanks.
DeepakProvide the query used for populating the child records. Issue might be due to caching.
Thanks
Shree -
How to delete the duplicate rows from the table
Hi,
I have 2 tbales namely component, component_audit
For each record in component table there are multiple entries in component_audit table.
I need to keep the first record and delete the others from the component_audit table
say for example
select a.component_id,a.dt_ti_stamp,a.component_name,a.column_before,b.comments from component_audit a,component b where a.component_id=b.component_id
( on the above result set only I shold apply the actual delete query )
PLease help me in this regards.
Thanks.delete from component_audit a where dt_ti_stamp not in (select
min(b.dt_ti_stamp)
from
component_audit b
where
a.component_id = b.component_id) -
Duplicate rows in Hierarchy Table created when running incremental load
I copied an out of the box dimension and hierarchy mapping to my custom folders (task hierarchy) this should create the same wids from dimension to hierarchy table and on full load does this using the sequence generator. The problem I am getting is whenever I run a incremental load instead of updating, a new record is created. What would be the best place to start looking at this and testing. A full load runs with no issues. I have also checked the DAC and run the SDE trunc always and SIL trunc for full load only.
Help appreciatedProvide the query used for populating the child records. Issue might be due to caching.
Thanks
Shree -
How to get duplicate rows in a large table
I have a table which consists of 26 columns and 2 milion records..while doing validation i suspect there are duplicate records in that table...
Is there any way to check duplicate rows in a table?I went through link..in all the messages query is for 2 or 3 columns...but my scenario is i have 26 columns ...and i suspect there is duplicate row inserting .for which value is same for all 26 columns .how should i do .?
do i need to do group by all 26 columns and do having count(*) ...26 times? -
Identifying and reporting Duplicate rows from table
I want to fetch all the duplicate row from the table and need to report all of it.
I am trying to run the below query but and not getting the expected output. Please help me.
Query
SELECT * FROM ADDT_RPT_REQ A WHERE
TRIM(A.EMAIL_ADDR) IN
(SELECT TRIM(EMAIL_ADDR) FROM ADDT_RPT_REQ B
WHERE TRIM(B.EMAIL_ADDR) = TRIM(A.EMAIL_ADDR)
AND A.ph_num IN
(SELECT PH_NUM FROM ADDT_RPT_REQ B
WHERE TRIM(A.PH_NUM ) = TRIM(B.PH_NUM)
There are in all 7 columns in the table where id is Unique Id.
The expected output is something like.
FST_NAME LAST_NAME EMAIL_ADDR WORK_PH_NUM ROW_ID LAST_UPD BU_ID
VALERIE HALL [email protected] 7819370177 2-21N-4312 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4327 29-JAN-04 0-R9NH
VALERIE HALL [email protected] 6034272034 2-21N-4309 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4317 04-APR-03 0-R9NH
VALERIE HALL [email protected] 8563748820 2-21N-4329 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4319 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4326 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4324 04-APR-03 0-R9NH
VALERIE HALL [email protected] 8604237395 2-21N-4330 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819373731 2-21N-4314 31-AUG-04 0-R9NH
VALERIE HALLORAN [email protected] 6194771101 2-21N-4331 31-OCT-05 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4316 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4321 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 7-1W4N-293 15-MAY-04 0-R9NH
VALERIE HALL [email protected] 2032341604 2-21N-4307 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4325 04-APR-03 0-R9NH
VALERIE HALL [email protected] 7819373737 2-21N-4315 29-JAN-03 0-R9NH
VALERIE HALL [email protected] 7819373737 7-1W4N-291 15-MAY-04 0-R9NH
VALERIE HALLORAN [email protected] 6194771101 2-21N-4332 31-OCT-05 0-R9NH
VALERIE HALL [email protected] 6038885349 2-21N-4310 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819373737324 2-21N-4328 31-AUG-04 0-R9NH
VALERIE HALL [email protected] 7819370177324 2-21N-4313 31-AUG-04 0-R9NHHi again!
Try that:
SELECT rowid, fst_name, last_name, email_addr, work_ph_num, row_id, last_upd, bu_id
FROM ADDT_RPT_REQ A
WHERE rowid > (SELECT MIN(rowid)
FROM ADDT_RPT_REQ B
WHERE B.fst_name = A.fst_name
AND B.last_name = A.last_name
AND B.email_addr = A.email_addr
AND B.work_ph_num = A.work_ph_num
AND B.row_id = A.row_id
AND B.last_upd = A.last_upd
AND B.bu_id = A.bu_id);This query should show you all duplicate rows. Use the rowid and DELETE to get rid of these rows.
DELETE FROM addt_rpt_req A
WHERE rowid IN (SELECT rowid
FROM (SELECT rowid, row_number() OVER (PARTITION BY fst_name, last_name, email_addr, work_ph_num, row_id, last_upd, bu_id
ORDER BY row_id) dup
FROM addt_rpt_req)
WHERE dup > 1);Yours sincerely
Florian W.
Edited by: Florian W. on 17.06.2009 14:17 -
To avoid duplicate rows in oracle 8i
Can you suggest how to prevent duplicate rows while in situations where multiple refreshes from a single export file using Oracle 8.1.7?
Do i need to specify Commit=Y, Constraints= N and IGNORE=N while importing data?
Your suggestion would be appreciated.
Thanks in advance.PK or not pk, if you set ignore=n, the import will be abort in case of table already exists, so you won't have any duplicate rows.
SQL> create table mytable as select * from all_users union all select * from all_users;
Table created.
SQL> select count(*) from mytable;
COUNT(*)
14
SQL> quit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> exp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
Export: Release 9.2.0.4.0 - Production on Tue Nov 14 13:32:40 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export done in UTF8 character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table MYTABLE 14 rows exported
Export terminated successfully without warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:32:48 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
SQL> drop table mytable;
Table dropped.
SQL> quit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:33:07 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
import done in UTF8 character set and AL16UTF16 NCHAR character set
. importing P97RPPRD's objects into P97RPPRD
. . importing table "MYTABLE" 14 rows imported
Import terminated successfully without warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:33:46 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
import done in UTF8 character set and AL16UTF16 NCHAR character set
. importing P97RPPRD's objects into P97RPPRD
IMP-00015: following statement failed because the object already exists:
"CREATE TABLE "MYTABLE" ("USERNAME" VARCHAR2(30), "USER_ID" NUMBER, "CREATED"
"" DATE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 6553"
"6 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 505 PCTINCREASE 0 FREELISTS 1 FREELI"
"ST GROUPS 1 BUFFER_POOL DEFAULT) LOGGING NOCOMPRESS"
Import terminated successfully with warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:34:13 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
SQL> select count(*) from mytable;
COUNT(*)
14
SQL>Now, if you haven't pk and set ignore=y, you will have duplicate lines, for sure :
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp ignore=y
Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:37:33 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
import done in UTF8 character set and AL16UTF16 NCHAR character set
. importing P97RPPRD's objects into P97RPPRD
. . importing table "MYTABLE" 14 rows imported
Import terminated successfully without warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:37:57 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
SQL> select count(*) from mytable;
COUNT(*)
28
SQL> Now, test with pk and ignore=y, import doesn't insert the duplicate key, so you won't have any duplicate rows :
SQL> drop table mytable;
Table dropped.
SQL> create table mytable as select * from all_users;
Table created.
SQL> alter table mytable add (primary key (username));
Table altered.
SQL> insert into mytable select * from all_users;
insert into mytable select * from all_users
ERROR at line 1:
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
SQL> quit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> exp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
Export: Release 9.2.0.4.0 - Production on Tue Nov 14 13:41:39 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export done in UTF8 character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table MYTABLE 7 rows exported
Export terminated successfully without warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp ignore=y
Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:41:49 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
Export file created by EXPORT:V09.02.00 via conventional path
import done in UTF8 character set and AL16UTF16 NCHAR character set
. importing P97RPPRD's objects into P97RPPRD
. . importing table "MYTABLE"
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 SYS
Column 2 0
Column 3 14-NOV-2005:16:14:52
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 SYSTEM
Column 2 5
Column 3 14-NOV-2005:16:14:52
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 OUTLN
Column 2 11
Column 3 14-NOV-2005:16:15:05
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 DBSNMP
Column 2 19
Column 3 14-NOV-2005:16:24:23
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 PS
Column 2 21
Column 3 14-NOV-2005:16:36:41
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 P97RPPRD
Column 2 24
Column 3 14-NOV-2005:16:53:41
IMP-00019: row rejected due to ORACLE error 1
IMP-00003: ORACLE error 1 encountered
ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
Column 1 PEOPLE
Column 2 25
Column 3 14-NOV-2005:16:57:09 0 rows imported
Import terminated successfully with warnings.
[data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> HTH,
Nicolas. -
How to Create primary key index with duplicate rows.
Hi All,
While rebuilding an index on a table , I am getting error that there are duplicate rows in a table.
Searching out the reason led me to an interesting observation.
Please follow.
SELECT * FROM user_ind_columns WHERE table_name='SERVICE_STATUS';
INDEX_NAME TABLE_NAME COLUMN_NAME COLUMN_POSITION COLUMN_LENGTH CHAR_LENGTH DESCEND
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO_RESETS 2 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS STATUS_TYPE_ID 3 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS ACTIVE_DT 4 7 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO 1 22 0 ASC
SELECT index_name,index_type,table_name,table_type,uniqueness, status,partitioned FROM user_indexes WHERE index_name='SERVICE_STATUS_PK';
INDEX_NAME INDEX_TYPE TABLE_NAME TABLE_TYPE UNIQUENESS STATUS PARTITIONED
SERVICE_STATUS_PK NORMAL SERVICE_STATUS TABLE UNIQUE VALID NO
SELECT constraint_name ,constraint_type,table_name,status,DEFERRABLE,DEFERRED,validated,index_name
FROM user_constraints WHERE constraint_name='SERVICE_STATUS_PK';
CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME STATUS DEFERRABLE DEFERRED VALIDATED INDEX_NAME
SERVICE_STATUS_PK P SERVICE_STATUS ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED SERVICE_STATUS_PK
1. Using index scan:
SELECT COUNT (*)
FROM (SELECT subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
no rows returned
Explain plan:
Operation OBJECT Name ROWS Bytes Cost OBJECT Node IN/OUT PStart PStop
SELECT STATEMENT Optimizer MODE=CHOOSE 519 K 14756
FILTER
SORT GROUP BY NOSORT 519 K 7 M 14756
INDEX FULL SCAN ARBOR.SERVICE_STATUS_PK 10 M 158 M 49184
2. Using Full scan:
SELECT COUNT (*)
FROM (SELECT /*+ full(s) */ subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status s
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
71054 rows returned.
Explain Plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 24123
SORT AGGREGATE 1
VIEW 519 K 24123
FILTER
SORT GROUP BY 519 K 7 M 24123
TABLE ACCESS FULL ARBOR.SERVICE_STATUS 10 M 158 M 4234
Index SERVICE_STATUS_PK is a unique and composite primary key VALID index. And the constraint is ENABLED and VALIDATED still having duplicate rows in table.
How it is possible?
Is it an Oracle soft Bug??
Regards,
Saket Bansalsaket bansal wrote:
Values are inserted as single rows inserts through an GUI interface.And you still claim to have over 71K duplicate records, without the GUI getting any kind of errors?
That does not add up and can only be explained by a "bug".
I tried inserting a duplicate record but failed.
SQL> insert into service_status (select * from service_status where rownum <2);
insert into service_status (select * from service_status where rownum <2)
ERROR at line 1:
ORA-00001: unique constraint (ARBOR.SERVICE_STATUS_PK) violatedAre you really sure there is no other way data in this table is populated/manipulated in bulk?
Maybe you are looking for
-
I changed my Apple ID on all my devices and services but iCloud still shows my old Apple ID. How can I get it to update?
-
Vertical stripes after latest Security Update 2008-004 for OS X Tiger
Hi there, I'm experiencing vertical stripes and color issues on my PB G4 17 inch screen after the security update 2008-004. Funny thing is, a screenshot looks fine. I already resetted PRAM and NVRAM. Didn't help. Does anyone know a solution? Thanks,
-
Parent-Child hierarchy based on two-column key
Hello Is it possible to create a parent-child hierarchy, if the primary key of the table consists of two columns? My table looks like: TRACE_ID | DIAG_ID | SUPER_DIAG_ID with TRACE_ID and DIAG_ID as PK. If I define only DIAG_ID as PK, I can add a log
-
I just bought a new iMac and am having troubles downloading creative cloud installer. Its coming up with error 214 - I can't find any solutions for this. Can anyone help me? Im on mac OS 10.9.4
-
How would i go about making a paralax scroller in actionscript 3.0?
i have a page with too much information on it i wanted to do something that was origanal to my site. so i picked a paralax scroller so that windows with different conetent on them and make a movie clip out of each perhapps in an embedded movie cli