Removing duplicate rows from SELECT
Hi, I was wondering if there was any way to remove duplicate rows from a select statement.
My table looks like this:
CREATE TABLE CUS_ID_TO_PC_ID (
CUSTOMER_ID VARCHAR2 (10) NOT NULL,
PC_ID VARCHAR2 (25) NOT NULL,
PASSWORD VARCHAR2 (25) NOT NULL,
REG_DATE DATE,
PRODUCT_DESC VARCHAR2 (25),
EXPIRE_DATE DATE,
SERIAL_NBR VARCHAR2 (12),
LDAP_USER VARCHAR2 (200),
COMMENTS VARCHAR2 (2000),
PC_ID_5_4 VARCHAR2 (25),
PC_ID_6_0 VARCHAR2 (25),
PASSWORD_5_4 VARCHAR2 (25),
PASSWORD_6_0 VARCHAR2 (25),
PC_ID_6_1 VARCHAR2 (25),
PASSWORD_6_1 VARCHAR2 (25),
OPERATING_SYSTEM VARCHAR2 (20),
STATUS VARCHAR2 (1)
Basically, I want to retrieve all columns from the table but remove all duplicate variations of
the pc_id/serial_nbr combinations.
For example, given this data:
PC_ID SERIAL_NBR CUSTOMER_NO
1234567 AAA C345
1234567 AAA C567
3333333 BBB C456
only the 1st and 3rd rows would be returned.
Any ideas?
Try something like this:
select * from your_table yt
where rowid in (select max(rowid)
from your_tabel yt2
where yt2.pc_id = yt.pc_id
and yt2.serial_nbr = yt.serial_nbr);
Similar Messages
-
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) -
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) -
Removing Duplicate Rows from resultSet
I have a query pulling data from 5 tables in 12 columns. I have rows where all of the data is duplicated with the exception of one date column. How would I go about deleting rows that are duplicates with the exception of this one column? I still need to pull the date from the date column with the Max(date).
i.e.
Bob Smith 1 2 3 4 12-Jul-2006
Bob Smith 1 2 3 4 02-Aug-2006
Bob Smith 1 2 3 4 21-Jan-2006
Form this resultset I only want one row
Thanks.this example might be of help.
SQL> select * from employees;
YEAR EM NAME PO
2001 02 Scott 91
2001 02 Scott 01
2001 02 Scott 07
2001 03 Tom 81
2001 03 Tom 84
2001 03 Tom 87
6 rows selected.
SQL> select year, empcode, name, position,
2 row_number() over (partition by year, empcode, name
3 order by year, empcode, name, position) as rn
4 from employees;
YEAR EM NAME PO RN
2001 02 Scott 01 1
2001 02 Scott 07 2
2001 02 Scott 91 3
2001 03 Tom 81 1
2001 03 Tom 84 2
2001 03 Tom 87 3
6 rows selected.
SQL> Select year, empcode, name, position
2 From (Select year, empcode, name, position,
3 row_number() over (partition by year, empcode, name
4 order by year, empcode, name, position) as rn
5 From employees) emp
6 Where rn = 1;
YEAR EM NAME PO
2001 02 Scott 01
2001 03 Tom 81
SQL> Delete From employees
2 Where rowid in (Select emp.rid
3 From (Select year, empcode, name, position,
4 rowid as rid,
5 row_number() over (partition by year, empcode, name
6 order by year, empcode, name, position) as rn
7 From employees) emp
8 Where emp.rn > 1);
4 rows deleted.
SQL> select * from employees;
YEAR EM NAME PO
2001 02 Scott 01
2001 03 Tom 81
SQL> if you can post a sample create tables and data it will help us provide you a some solutions. -
Need to remove duplicate rows from distinct query
Hello,
I have the following query:
SELECT tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
(CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr
FROM tis.tiab
JOIN tis.tior on tiab.abnr = tior.abnr
WHERE tior.inplnr IN (3797886)
ORDER BY tiab.ABNR )
ORDER BY abnr;
It returns the following:
14684940 Pizza Station Inc The Lafayette 26170 St Marys 304 684-2411
15123161 Chris Test 554 Easy St n 43333 Columbus 614 555-5555
15123162 Chris Test2 5556 Easy St 43333 Columbus 614 555-5151 2553304 --> keep this one
15123162 Chris Test2 5556 Easy St 43333 Columbus 614 555-5151 -- not show this
I have tried several different things as well as looking through the forums but have not found anything that will only give me unique records based only on the first column. This query works fine as long as there
are not 2 records returned with column1 being identical.
Final results should look like this:
14684940 Pizza Station Inc The Lafayette 26170 St Marys 304 684-2411
15123161 Chris Test 554 Easy St n 43333 Columbus 614 555-5555
15123162 Chris Test2 5556 Easy St 43333 Columbus 614 555-5151 2553304
Thanks in advance for the assistance.Hello,
Try:
SELECT abnr, namn, ADR, boxpnr, boxort,RIKTNR, TELNR,tigilopnr
FROM (
SELECT tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
(CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr,
ROW_NUMBER () OVER (PARTITION BY tiab.abnr ORDER BY (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) NULLS LAST) row_num
FROM tis.tiab
JOIN tis.tior on tiab.abnr = tior.abnr
WHERE tior.inplnr IN (3797886))
WHERE row_num <= 1
ORDER BY abnr;Or, with your current query:
SELECT abnr, namn, ADR, boxpnr, boxort,RIKTNR, TELNR,tigilopnr
FROM (
SELECT distinct tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
(CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr,
ROW_NUMBER () OVER (PARTITION BY tiab.abnr ORDER BY (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) NULLS LAST) row_num
FROM tis.tiab
JOIN tis.tior on tiab.abnr = tior.abnr
WHERE tior.inplnr IN (3797886))
WHERE row_num <= 1
ORDER BY abnr; -
Remove Duplicate Rows from Left Outer Join
Hi All,
I am new to Oracle..I have two tables as follow:
TableA(EmpID, Empname)
TableB(EmpID, DeptID, DeptName). A employee can work in multiple dept.
table A has 1 row as EmpID 1 and TableB has two rows for EmpID 1.
I have a search page which takes dept ID as parameter and return employee name...Dept ID is not mandatory feld for Search. If DeptID is passed it should return the employee who belongs to that Dept otherwise it should return 1 employee..
Now I have used as follow:
:IN_DEPTID is passed as parameter
Select EmpName from TableA Left Join tableB on a.EmpID = B.EmpID
WHERE
CASE WHEN :IN_DEPTID IS NULL
IN_DEPTID IS NULL
ELSE|
DEPTID = :IN_DEPTID
Now problem is when Dept ID is passed it correctly returns a row but if no deptid is passed it returns 2 rows but i want ony one row as there is only one employee.
Please help;
Edited by: user10239708 on 10 Sep, 2008 12:24 AM
Edited by: user10239708 on 10 Sep, 2008 12:28 AMTry this
Select
from
tableA a
where
(exists (select 1 from tableB b where a.empid = b.empid and deptid = :IN_DEPTID )
or
:IN_DEPTID is null) you database design is not good you should keep the emp, department mapping in different table.
Regards
Singh -
Rerieve Duplicate Rows from a SELECT statement
Hi, I want to see all the duplicate rows from my SELECT statement. Looks like Oracle by default suppresses the duplicate rows. Here is my SQL statement.
I like to see all the 5 rows. Please help.
select a.partid, a.pdesc
from product a
where a.partid in ('10-30000-4',
'10-30000-4',
'10-30000-4',
'10-30000-4',
'10-30000-5')Looks like Oracle by default suppresses the duplicate rowsSure no, if you have duplicate rows, Oracle will show you the dup rows.
Please, paste your data and the query result.
And this is no because you'll put multiple time the same condition that Oracle will show you multiple time the same row (in case of non-duplicate).
Nicolas. -
Removing duplicate values from selectOneChoice bound to List Iterator
I'm trying to remove duplicate values from a selectOneChoice that i have. The component binds back to a List Iterator on the pageDefinition.
I have a table on a JSF page with 5 columns; the table is bound to a method iterator on the pageDef. Then above the table, there are 5 separate selectOneChoice components each one of which is bound to the result set of the table's iterator. So this means that each selectOneChoice only contains vales corresponding to the columns in the table which it represents.
The selectOneChoice components are part of a search facility and allow the user to select values from them and restrict the results that are returned. The concept is fine and i works. However if i have repeating values in the selectOneChoice (which is inevitable given its bound to the table column result set), then i need to remove them. I can remove null values or empty strings using expression language in the rendered attribute as shown:
<af:forEach var="item"
items="#{bindings.XXXX.items}">
<af:selectItem label="#{item.label}" value="#{item.label}"
rendered="#{item.label != ''}"/>
</af:forEach>
But i dont know how i can remove duplicate values easily. I know i can programatically do it in a backing bean etc.... but i want to know if there is perhaps some EL that might do it or another setting that ADF gives which can overcome this.
Any help would be appreciated.
Kind RegardsHi,
It'll be little difficult removing duplicates and keeping the context as it is with exixting standard functions. Removing duplicates irrespective of context changes, we can do with available functions. Please try with this UDF code which may help you...
source>sort>UDF-->Target
execution type of UDF is Allvalues of a context.
public void UDF(String[] var1, ResultList result, Container container) throws StreamTransformationException{
ArrayList aList = new ArrayList();
aList.add(var1(0));
result.addValue(var1(0));
for(int i=1; i<var1.length; i++){
if(aList.contains(var1(i)))
continue;
else{
aList.add(var1(i));
result.addValue(var1(i));
Regards,
Priyanka -
Remove duplicate entries from dropdownlist in web dynpro abap
How to remove duplicate entries from dropdownlist in web dynpro abap? Can someone please help me
I have maintained the data in the z table wherein the records of particular fields are repeated but when i show that record in the Web Dynpro application dropdown list, the user should only be able to view the unique data for selection of that particular field.Hi,
try this code in init method.
use the
Delete adjacent duplicates.
<set the table>
select <f1> from <table> into TABLE <Itab> whre <condition>.
DELETE ADJACENT DUPLICATES FROM <Itab> COMPARING <f1>.
lo_nd_vbap->bind_table( new_items = <itab> set_initial_elements = abap_true ). -
How to remove duplicates records from output ?
how to remove duplicates records from output ? i used delete adjacent but duplicates records are coming again ..suggest me
hi shruthi,
thanks for ur answer ..but duplicates records coming again
here is my code >> plz check it out
*& Report ZCRM_TROUBLE_TICKET
REPORT zcrm_trouble_ticket.
TYPES : BEGIN OF ty_qmih,
qmnum TYPE qmnum,
equnr TYPE equnr,
iloan TYPE iloan,
ausvn TYPE ausvn,
ausbs TYPE ausbs,
auztv TYPE auztv,
auztb TYPE auztb,
iwerk TYPE iwerk,
END OF ty_qmih,
BEGIN OF ty_qmel,
qmnum TYPE qmnum,
qmtxt TYPE qmtxt,
indtx TYPE indltx,
priok TYPE priok,
strmn TYPE strmn,
strur TYPE strur,
ltrmn TYPE ltrmn,
ltrur TYPE ltrur,
objnr TYPE qmobjnr,
arbpl TYPE lgwid,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
END OF ty_qmel,
BEGIN OF ty_ihpa,
parnr TYPE i_parnr,
parvw TYPE parvw,
objnr TYPE qmobjnr,
END OF ty_ihpa,
BEGIN OF ty_crhd,
arbpl TYPE arbpl,
objid TYPE cr_objid,
END OF ty_crhd,
BEGIN OF ty_crtx,
ktext TYPE cr_ktext,
objid TYPE cr_objid,
END OF ty_crtx,
BEGIN OF ty_qmfe,
fecod TYPE fecod,
fegrp TYPE fegrp,
qmnum TYPE qmnum,
END OF ty_qmfe,
BEGIN OF ty_qmur,
urcod TYPE urcod,
urgrp TYPE urgrp,
urtxt TYPE urstx,
qmnum TYPE qmnum,
END OF ty_qmur,
BEGIN OF ty_iloa,
tplnr TYPE tplnr,
iloan TYPE iloan,
END OF ty_iloa,
BEGIN OF ty_output,
qmnum TYPE qmnum,
equnr TYPE equnr,
iloan TYPE iloan,
ausvn TYPE ausvn,
ausbs TYPE ausbs,
auztv TYPE auztv,
auztb TYPE auztb,
iwerk TYPE iwerk,
qmtxt TYPE qmtxt,
indtx TYPE indltx,
priok TYPE priok,
strmn TYPE strmn,
strur TYPE strur,
ltrmn TYPE ltrmn,
ltrur TYPE ltrur,
objnr TYPE qmobjnr,
arbpl TYPE lgwid,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
parnr TYPE i_parnr,
parvw TYPE parvw,
arbpl TYPE arbpl,
objid TYPE cr_objid,
arbpl1 TYPE arbpl,
ktext TYPE cr_ktext,
fecod TYPE fecod,
fegrp TYPE fegrp,
urcod TYPE urcod,
urgrp TYPE urgrp,
urtxt TYPE urstx,
tplnr TYPE tplnr,
END OF ty_output.
DATA : it_qmih TYPE STANDARD TABLE OF ty_qmih,
it_qmel TYPE STANDARD TABLE OF ty_qmel,
it_ihpa TYPE STANDARD TABLE OF ty_ihpa,
it_crhd TYPE STANDARD TABLE OF ty_crhd,
it_crtx TYPE STANDARD TABLE OF ty_crtx,
it_qmfe TYPE STANDARD TABLE OF ty_qmfe,
it_qmur TYPE STANDARD TABLE OF ty_qmur,
it_iloa TYPE STANDARD TABLE OF ty_iloa,
it_output TYPE STANDARD TABLE OF ty_output,
wa_qmih TYPE ty_qmih,
wa_qmel TYPE ty_qmel,
wa_ihpa TYPE ty_ihpa,
wa_crhd TYPE ty_crhd,
wa_crtx TYPE ty_crtx,
wa_qmfe TYPE ty_qmfe,
wa_qmur TYPE ty_qmur,
wa_iloa TYPE ty_iloa,
wa_output TYPE ty_output.
INITIALIZATION.
REFRESH : it_qmih,
it_qmel,
it_ihpa,
it_crhd,
it_crtx,
it_qmfe,
it_qmur,
it_iloa,
it_output.
CLEAR: wa_qmih,
wa_qmel,
wa_ihpa,
wa_crhd,
wa_crtx,
wa_qmfe,
wa_qmur,
wa_iloa,
wa_output.
start-of-selection.
SELECT qmnum
equnr
iloan
ausvn
ausbs
auztv
auztb
iwerk
FROM qmih
INTO TABLE it_qmih.
SORT it_qmih BY qmnum .
DELETE ADJACENT DUPLICATES FROM it_qmih COMPARING qmnum equnr iloan ausvn ausbs auztv auztb iwerk.
SELECT qmnum
qmtxt
indtx
priok
strmn
strur
ltrmn
ltrur
objnr
arbpl
vkorg
vtweg
spart
FROM qmel
INTO TABLE it_qmel
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
SORT it_qmel BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmel COMPARING qmnum
qmtxt
indtx
strmn
strur
ltrmn
ltrur
objnr
arbpl
vkorg
vtweg
spart.
IF it_qmel IS NOT INITIAL.
SELECT parnr
parvw
objnr
FROM ihpa
INTO TABLE it_ihpa
FOR ALL ENTRIES IN it_qmel
WHERE objnr = it_qmel-objnr.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_ihpa COMPARING parnr
parvw
objnr.
IF it_qmel IS NOT INITIAL.
SELECT arbpl
objid
FROM crhd
INTO TABLE it_crhd
FOR ALL ENTRIES IN it_qmel
WHERE objid = it_qmel-arbpl.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_crhd COMPARING arbpl
objid.
IF it_qmel IS NOT INITIAL.
SELECT ktext
objid
FROM crtx
INTO TABLE it_crtx
FOR ALL ENTRIES IN it_crhd
WHERE objid = it_crhd-objid.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_crtx COMPARING ktext
objid.
IF it_qmih IS NOT INITIAL.
SELECT fecod
fegrp
qmnum
FROM qmfe
INTO TABLE it_qmfe
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
ENDIF.
SORT it_qmfe BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmfe COMPARING fecod
fegrp.
IF it_qmih IS NOT INITIAL.
SELECT urcod
urgrp
urtxt
qmnum
FROM qmur
INTO TABLE it_qmur
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
ENDIF.
SORT it_qmur BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmur COMPARING urcod
urgrp
urtxt.
IF it_qmih IS NOT INITIAL.
SELECT tplnr
iloan
FROM iloa
INTO TABLE it_iloa
FOR ALL ENTRIES IN it_qmih
WHERE iloan = it_qmih-iloan.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_iloa COMPARING tplnr
iloan.
LOOP AT it_qmih INTO wa_qmih.
wa_output-qmnum = wa_qmih-qmnum.
wa_output-equnr = wa_qmih-equnr.
wa_output-iloan = wa_qmih-iloan.
wa_output-ausvn = wa_qmih-ausvn.
wa_output-ausbs = wa_qmih-ausbs.
wa_output-auztv = wa_qmih-auztv.
wa_output-auztb = wa_qmih-auztb.
wa_output-iwerk = wa_qmih-iwerk.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmel INTO wa_qmel WITH KEY qmnum = wa_qmih-qmnum.
wa_output-qmtxt = wa_qmel-qmtxt.
wa_output-indtx = wa_qmel-indtx.
wa_output-priok = wa_qmel-priok.
wa_output-strmn = wa_qmel-strmn.
wa_output-strur = wa_qmel-strur.
wa_output-ltrmn = wa_qmel-ltrmn.
wa_output-ltrur = wa_qmel-ltrur.
wa_output-objnr = wa_qmel-objnr.
wa_output-arbpl = wa_qmel-arbpl.
wa_output-vkorg = wa_qmel-vkorg.
wa_output-vtweg = wa_qmel-vtweg.
wa_output-spart = wa_qmel-spart.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_ihpa INTO wa_ihpa WITH KEY objnr = wa_qmel-objnr.
wa_output-parnr = wa_ihpa-parnr.
wa_output-parvw = wa_ihpa-parvw.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_crhd INTO wa_crhd WITH KEY objid = wa_qmel-arbpl.
wa_output-arbpl = wa_crhd-arbpl.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_crtx INTO wa_crtx WITH KEY objid = wa_crhd-objid.
wa_output-ktext = wa_crtx-ktext.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmfe INTO wa_qmfe WITH KEY qmnum = wa_qmih-qmnum.
wa_output-fecod = wa_qmfe-fecod.
wa_output-fegrp = wa_qmfe-fegrp.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmur INTO wa_qmur WITH KEY qmnum = wa_qmih-qmnum.
wa_output-urcod = wa_qmur-urcod.
wa_output-urgrp = wa_qmur-urgrp.
wa_output-urtxt = wa_qmur-urtxt.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_iloa INTO wa_iloa WITH KEY iloan = wa_qmih-iloan.
wa_output-tplnr = wa_iloa-tplnr.
APPEND wa_output TO it_output.
CLEAR wa_output.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM it_output COMPARING qmnum
equnr
ausvn
ausbs
auztv
auztb
iwerk
qmtxt
indtx
priok
strmn
strur
ltrmn
ltrur
vkorg
vtweg
spart
parnr
parvw
arbpl
ktext
fecod
fegrp
urcod
urgrp
urtxt
tplnr.
*CALL FUNCTION 'STATUS_TEXT_EDIT'
EXPORTING
CLIENT = SY-MANDT
FLG_USER_STAT = ' '
objnr =
ONLY_ACTIVE = 'X'
spras = en
BYPASS_BUFFER = ' '
IMPORTING
ANW_STAT_EXISTING =
E_STSMA =
LINE =
USER_LINE =
STONR =
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
id =
language =
name =
object =
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
tables
lines =
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*LOOP AT IT_OUTPUT INTO WA_OUTPUT.
*WRITE : / WA_OUTPUT-qmnum,
WA_OUTPUT-equnr,
WA_OUTPUT-iloan,
WA_OUTPUT-ausvn,
WA_OUTPUT-ausbs,
WA_OUTPUT-auztv,
WA_OUTPUT-auztb,
WA_OUTPUT-qmtxt,
WA_OUTPUT-indtx,
WA_OUTPUT-strmn,
WA_OUTPUT-strur,
WA_OUTPUT-ltrmn,
WA_OUTPUT-ltrur,
WA_OUTPUT-objnr,
WA_OUTPUT-arbpl,
WA_OUTPUT-parnr,
WA_OUTPUT-parvw,
WA_OUTPUT-objid,
WA_OUTPUT-ktext,
WA_OUTPUT-fecod,
WA_OUTPUT-fegrp,
WA_OUTPUT-urcod,
WA_OUTPUT-urgrp,
WA_OUTPUT-urtxt,
WA_OUTPUT-tplnr.
*ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = 'E:\CRM1.TXT'
FILETYPE = 'ASC'
APPEND = ' '
write_field_separator = '|'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
data_tab = it_output
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
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 -
How we remove duplicate segments from an idoc
how we remove duplicate segments from an idoc.
Hi Manju.
Go to T-code WE19------->Give your Existing Idoc Number or Basic Type --->Get in Select your (Nodes) segment and Click on "Delete Indicator"
Regards,
Seegal -
How do I remove a row from the database?
Guys and Gals,
I'm using Studio Edition Version 11.1.1.3.0.
The code below will delete a row from my table, but how do I actually delete the row from the database as well?
DCBindingContainer dcbc = (DCBindingContainer)getBindings();
DCIteratorBinding dcib = dcbc.findIteratorBinding("TipsSelectorIterator");
dcib.removeCurrentRow();
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
Object result = operationBinding.execute();
AdfFacesContext adffacesctx = AdfFacesContext.getCurrentInstance();
adffacesctx.addPartialTarget(this.getQueryTable()); In this post, I believe Frank sums up what I should do: Remove row from af:table
>
The problem in your case is that this removes the row from the iterator but not your business service. EJB exposes explicit methods to remove an entity. A method lime removeEmployees(employee) >expsed on the EJB model must be called.
You can drag and drop the "removeEmployees" method then as a button to your page. Rename the text label to "Remove" or "Delete". In the opened dialog box, point the method argument to the >following EL #{bindings.iteratorName.currentRow.dataProvider}. Next time you press the button, the row is deleted from the iterator and the business service
Huh? So to delete the row, I need to expose a method. But where? Do I do this in the AppModuleImpl so I can expose it to the Client Interface? But then how do I access entities? And what data type is the #{bindings.iteratorName.currentRow.dataProvider}?
If anyone could point me in a general direction, it'd be great.Frank and Shay,
Thank you both for your posts. I'm amazed there's such a great place to get help. Between the forums, ADF code corner, Not Yet Documented ADF Samples, various blogs and tutorials, it's obvious you guys really care about what you do.
On my example, that approach doesn't seem to work. I tried following it like so in one of the video tutorials by Shay: http://blogs.oracle.com/shay/2010/04/doing_two_declarative_operatio.html. Following Shay's approach, in my particular case, deletes only from the table. Perhaps it is due to my iterator / collection setup?
TipsSelector (1 to 1) -> TipsView (1 to *)-> DependentBom -(1 to * Recursive)> RecursiveBom
TipsSelector references the same View Object as TipsView, but it is set as a 1 to 1 relationship so that I can show TipsView on the page one record at a time. This is the same setup as Tuhra2's hierarchy veiwer example. TipsView / DependentBom is a classic parent / child setup. RecursiveBom is DependentBom referencing itself. Think of it as departments within departments within departments etc...
I have dragged TipsSelector's Named Criteria (All Queriable Attributes) onto my page and created an ADF Query with Table. A remove button on the table's toolbar calls the two actions, Delete (from TipsSelector's iterator) and then Commit. I have modified the code slightly from my previous post but the end result seems to be the same.
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("Delete");
operationBinding.execute();
bindings = getBindings();
operationBinding = bindings.getOperationBinding("Commit");
operationBinding.execute();
AdfFacesContext adffacesctx = AdfFacesContext.getCurrentInstance();
adffacesctx.addPartialTarget(this.getQueryTable());Page Def file
<action id="Commit" InstanceName="AppModuleDataControl"
DataControl="AppModuleDataControl" RequiresUpdateModel="true"
Action="commitTransaction"/>
<action IterBinding="TipsSelectorIterator" id="Delete"
InstanceName="AppModuleDataControl.TipsSelector"
DataControl="AppModuleDataControl" RequiresUpdateModel="false"
Action="removeCurrentRow"/>On ppr of the query table, the row is gone. However, when I press the Search button on the query again, the record reappears.
This is beyond me. Am I somehow deleting from the query results but not the database? -
How to remove a row from a rowset obtained via a CachedRowSetDataProvider
I have a table filled from a database that it is bound to.
I have the CachedRowSetDataProvider that supplies the rows.
I want to remove a row from the result set and can't figure out how.
There is a method ... removeRow(RowKey row).
and there is a method ... getRowKey(java.lang.String rowId)
How do I determine what the string id is for, say, row 3?
thanks
jim murrayThats the tutorial I am working with.
My problem is that the statement tripDataProvider.refresh();
executed when the person drop down changes doesn't seem to clearing the previous persons results.
So I want to clear the rowset myself by deleting the rows individually.
I can find a method to delete a row if I supply the RowKey.
There is a method to get the rowkey if I know the RowID, which is a string.
Unfortunately I dont know the string to use for an arbitrary row.
There should be a simpler way to clear the data from a rowset.
regards
jim murray -
How to remove a row from a rowset
HI,
I am trying to do a very simple thing, but I got stuck.
The problem:
I want to remove a row from a rowset, without removing the row itself. Especially I do not want to remove any entities.
I need this functionality in several situations, for example when I want to move a row from one rowset to another.
Another situation is when I have a viewlink not based on an association. When a row is modified so it does not fit to the viewlink's where clause anymore, I need a way to remove it manually (without removig any associated entities),
I hope someon can help me on this,
thanks,
FrankSascha:
The only workaround I can think of is a true hack, and you'd be entering into a unchartered territory. But, it may be worth a try.
First, you need to create a subclass of oracle.jbo.server.ViewObjectImpl in the oracle.jbo.server package. This is because you need to override one of the package private methods. Suppose you define oracle.jbo.server.TempBaseViewObjectImpl which extends ViewObjectImpl.
Override the following method:
int[] getDeleteParticipants()
This method returns an array of EO bases for which ViewRow's delete should cause deletion of EntityRow's.
So, before you remove a ViewRow, you should set some flag in your TempBaseViewObjectImpl, so that getDeleteParticipants() would return "new int[0];" This will cause no EntityRow's to be deleted. Only the ViewRow will be removed from the collection.
Note that you should reset this flag after the operation, so that you can delete the EntityRow's (when necessary).
Your real VO should then subclass TempBaseViewObjectImpl.
Once we fix this problem and provide a real API, you should remove TempBaseViewObjectImpl and extend your real VO from ViewObjectImpl instead of TempBaseViewObjectImpl.
Thanks.
Sung
Maybe you are looking for
-
ICloud is no longer syncing my calendars.
iCloud is no longer syncing my calendars. They are showing up as "iCloud" calendars in iCal, but aren't syncing either to the web portal or to other devices. In System Preferences, the iCloud calendar and reminder toggles will not stay checked. They
-
Cannot install Itunes 8 on windows - please help
I had an issue with Itunes re-installing each time I would start Itunes, so I deleted off computer via add/delete feature on windows. I also deleted Bonjour and everything apple so I could start again. Now trying to install from scratch the Itunes 80
-
How can I get this effect in Photoshop CS5.1?
I want to turn a real image like http://bit.ly/pEx1ol into something like http://bit.ly/nfkoa4 Is there a way to do that or do I have to start from scratch?
-
Adapter Engine Component Missing
Hi All, In the Integration Directory, The Adapter Engine field dropbox is not showing the central Adapter Engine component.Because of this the adapters (other than HTTP and IDoc adapters)can't be used during configuration. Can anyone help? Thanks and
-
IMovie 09 - synching new sound to video clip
Hi all iMovie users. I am trying to synch my improved sound track to video. I drag the new sound track to the approx right place in the iMovie clips having muted the clip but if I drag the green sound bar it is too fierce; if I use the arrow keys to