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.
Similar Messages
-
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); -
Count the number of rows resulting from a select statement
Hi,
Is there any way of counting the number of rows resulting from a select statement. i.e I have a select distinct statement and I then want to perform an IF statement on the number of rows resulting from the select statement.
Any help appreciated
Thanks
GaryDeclare
var1 number;
Begin
select count(distinct column_name) into
var1 from table_name;
If var1 > x Then
End IF;
End;
Hope I understood the problem correctly
null -
How to update duplicate row from table
Hi,
how to update duplicate row from table?
First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
can you give me suggestion on it?
Thanks in advance.
your early response is appreciated...In order to find a duplicate row, see:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
(or search this forum, your question has been asked before)
In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase. -
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) -
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 to pass an array to a function from a SELECT statement
Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
Here is what I want. If I have a function
function AAA(arrayVar <ArrayType>) return number;
I want to be able to call this function this way
select AAA((2,3,4))
from dual
or this way
select AAA((10,12))
from dual
In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
Thank you in advance.> What <ArrayType> should I use?
SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
You can however use all SQL structures and types in PL/SQL.
Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
Oracle® Database Application Developer's Guide - Object-Relational Features -
Adding count from two select statements
Hi,
How to add counts from two select statements in a single SQL statement.
For ex: I have
SELECT COUNT(DISTINCT COL1) FROM table1
and
SELECT COUNT(DISTINCT COL2) FROM table2.
I want to add the counts from these two sqls in a single select query. How to do this.
Thanks & Regards,
Sunil.select ((SELECT COUNT(DISTINCT COL1) FROM table1) + (SELECT COUNT(DISTINCT COL2) FROM table2)) as "total" from dual;
regards, -
i have a table A suppose it has 3 columns
id name sal
==========
1 A 100
1 A 100
2 B 200
2 B 200
2 B 200
3 C 300
I want to find duplicate rows from the above table without passing any column in to the where clause .
please help me to find out this query.maybe you should try the database forum...
-
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) -
Selecting duplicate rows from table
Hi all,
How to select the duplicates rows present in the table...SQL> select * from customer;
CUST_ID CUST_NAME LOC
1 Jeff Miami
2 Andrew Michigan
3 Julia Chicago
1 Linda Miami
1 Martha Miami
3 Randy Chicago
3 John Chicago
7 rows selected.
SQL> select * from customer where rowid != (select min(rowid) from customer C where C.cust_id = customer.cust_id);
CUST_ID CUST_NAME LOC
1 Linda Miami
1 Martha Miami
3 Randy Chicago
3 John Chicago
SQL> -
Querying many tables at once from a select statement for specific values
Hi all,
I'm very new to PL/SQL and have a daunting task ahead of me. I'm pretty sure our database normalization scheme is all out of whack, which I dont have the experience to fix yet, but this is the task ahead of me without getting to change or fix our structure:
in the universe has 1000+ tables.
need--> Some of those tables have fields that contain a value that has to be changed.
The only thing I have to go on is the column name will contain 'EMP'... but there is no specific naming convention for the column names.
When I search on:
select * from all_tab_columns where column_name like UPPER('%EMP%')
It returns 750 rows. (So 750 rows = 750 columns in 500 different tables (some tables have 2 or more columns in it))
tables names are random (table1, table2, etc).
columns names are random with EMP in it (column1,column2,etc).
I have 75 possible field values that I need to check each of those 750 columns for.
Maybe this is too messy, but I'm looking at subqueries, joins, arrays, cursors, etc, anything to minimize the amount of work I have to do.
I think this is too much to do a join with, but that seems to be what all the documentation is pointing me to.
can you point me to a simple example of what i could
write?
the logic i see it would be
run the select statement to grab the column names that meet EMP.
one at a time, search each column in the corresponding table for the 75 values.
return the results of rows for each column/table that meet one of the 75 unique values.
I'll have to also update each of the 75 values to (used to be values 1, 2, 3 ... to new values X1, X2, X3, etc.)
Any help at all would be very helpful,
aspiring pl/sql programmer but having a rough time of itI think you're looking to do something like the following pseudocode:
BEGIN
FOR tblrec IN (SELECT table_name, column_name
FROM all_tab_columns
WHERE column_name LIKE '%EMP%')
LOOP
FOR rec IN (SELECT ROWID
FROM tblrec.table_name
WHERE REGEXP_LIKE(tblrec.column_name, '(expr1|expr2|...)')
LOOP
DBMS_OUTPUT.PUT_LINE(
'Found expression on ROWID ' || rec.rowid
|| ' in column ' || tblrec.column_name
|| ' on table ' || tblrec.table_name);
END LOOP;
END LOOP;
END; -
Eliminate duplicate rows from the report 6i output
Hi All,
I have generated a report output with the group by and summary options.
For Ex: report has num and amount columns
I had to sum the amount group by num
NUM AMOUNT
1 100
1 50
2 10
2 100
After group by and summary functions the report is generating the output as follows...
NUM AMOUNT
1 150
1 150
2 110
2 110
I want to eliminate the duplicate rows and want the output as follows...
NUM AMOUNT
1 150
2 110
I tried all the ways to implement distinct, but not able to.
I donot want to implement distinct on the query but want to perform at the report level.
Please help me in this ASAP.
Thanks,
VijayIt would be helpful if you post your query, should by something like
SELECT NUM, SUM(AMOUNT)
FROM TABLE
GROUP BY NUM
ORDER BY 1this would not create duplicates with your given example data. -
How to processing the results from the select statement in SQL query?
Hi
This might be too simple, but my knowledge of the SQL is very limited...
I have table where I do have details from calls (Lync QoE).
I can take all calls from the table, but I would like to count the concurrent calls on the table. This is how I got it work on the Excel to work (but I would like to do that on the SQL statement to get it more dynamic use):
Table have these line and this is what I get out from the Select):
[callid],[start],[end]
1ABC,1.1.2014 01:00:15, 1.1.2014 01:01:00
5DEF,1.1.2014 01:00:45, 1.1.2014 01:05:00
FDE2,1.1.2014 01:03:15, 1.1.2014 01:04:00
KDJ8,1.1.2014 01:04:15, 1.1.2014 01:06:00
FDJ8,2.1.2014 01:04:15, 2.1.2014 01:06:00
KDSE,3.1.2014 01:04:15, 3.1.2014 01:06:00
The information I would like to get, is what is the maximum amount of the concurrent calls per day.
On the excel I basically count line by line how many concurrent calls each line have had, and then pickup the highest one. On above example the calls 5DEF, FDE2 and FDE2 have been active at the same time which gives 3 for the first day.
The table is ordered by the start. So let say the code is on the third line (FDE2). I need to count calls from before which end time is after the start time (of FDE2), but also I need to count calls after (FDE2) which are started before the current
call has ended.
PetriUnfortunately your post is off topic as it's not specific to SQL Server Samples and Community Projects.
This is a standard response I’ve written in advance to help the many people who post their question in this forum in error, but please don’t ignore it. The links I provide below will help you determine the right forum to ask your question in.
For technical issues with Microsoft products that you would run into as an end user, please visit the Microsoft Answers forum ( http://answers.microsoft.com ) which has sections for Windows, Hotmail,
Office, IE, and other products.
For Technical issues with Microsoft products that you might have as an IT professional (like technical installation issues, or other IT issues), please head to the TechNet Discussion forums at http://social.technet.microsoft.com/forums/en-us, and
search for your product name.
For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), please head to the MSDN discussion forums at http://social.msdn.microsoft.com/forums/en-us, and
search for your product or issue.
If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here: http://community.dynamics.com/
If you think your issue is related to SQL Server Samples and Community Projects and I've flagged it as Off-topic, I apologise. Please repost your question and include as much detail as possible about your problem so that someone can assist you further.
If you really have no idea where to post your question please visit the Where is the forum for…? forum http://social.msdn.microsoft.com/forums/en-us/whatforum/
When you see answers and helpful posts, please click Vote As Helpful,
Propose As Answer, and/or Mark As Answer
Jeff Wharton
MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt), MCT, MCPD, MCSD, MCSA, MCITP, MCDBA
Blog: Mr. Wharty's Ramblings
Twitter: @Mr_Wharty
MC ID:
Microsoft Transcript -
Gettingant to row number in select statement
Hello,
I want to retrieve the row number of a record in the select statement. Can anybody help me in writing a query for this in php.
Thanks
Omkarsoft<a> developerLookup ROWNUM.
Followup questions belong in a SQL forum, not the PHP forum :)
Maybe you are looking for
-
How to save music from corrupt ipod
i recently just bought an 80GB ipod video and i just finished putting in my collection of about 40GB of music which i idiotically didnt save on my comp, anyways...i plugged my ipod into my comptuer the other day and it said that it was corrupted and
-
HT1338 want to upgrade OS X 10.5.8 dont have disk
I have OS X 10.5.8 and I need to upgrade OS X but dont have my cd Install Waht can I do?
-
How do I fix missing fonts linked to a PDF?
My message reads: "Missing Font. Edit the source to apply a different font." I cannot edit the linked PDF's fonts or type (it's flattened). I can't export my InDesign file or make a booklet if I have these errors of missing fonts. Anyone know of
-
Create outbound delivery using VL10D
Hi Gurus, If i have 4 STOs,i call up VL10D,select these 4 STOs,and click backgound button, system will create one outbound delivery with 4 items. but i want 4 outbound deliveries to be created,how to achieve this? Thank you in advance! Regards, Drags
-
Hi Experts, User is getting QE573 and QE570 printed messages while releasing every process order from COR5 T-Code. I tried to investigate this and found that these are printing messages for "Sample Drawing Instruction" and "Inspection instruction", a