Remove duplicate rows based on latest date
Hi Julius, There are various ways to achive this but I would think an optimized way of doing it by making use of (Sorter and) an Aggregator transformation(s), see how.. Sort your input records at SQ level if it's a relational source or else use a Sorter tx (that's why I mentioned Sorter tx in braces in abvoe line) to sort the input rows on Stage_ID and Date, both in Ascending order, thus you get the latest date record at the end in the list per common Stage_IDs. Now, connect to Aggregator (must be right next to the sorter in order to not to loose the sorted data), and enable the Group By for Stage_ID port. By nature, aggregator tx will push the last record of the group by port or last record of the complete data set if no group by port mentioned. So, you will get recent row per Stage_ID. Try and get back to us if you have any questions or run into issues,-Rajani
I have a target table I need to split up: stage_id / date / case / blah / blah100 / 01-jan-2015 / 223 / 32 / 323100 / 01-apr-2015 / 224 / 32 / 322 the stage_id column cannot have more than 1 of the same record, so, i need to keep the latest record (01-apr-2015) in this target table, then remove the old one and put it into a dimension table any suggestions for how to accomplish this? please let me know if more info is needed thanks!
Similar Messages
-
Select distinct rows based on latest date
Hi
I need to produce data from two tables and return results where only data for the latest OriginationDate is returned for each unique client. I have been trying all sorts of combinations but with no success. Any help would be appreciated
e.g
select
c.client_no
,c.forename
,c.surname
,c.tel_no1
,c.tel_no2
,c.tel_no3
,o.ordernumber
,o.propertyidentifier
,o.contractorlongname
,o.OrderStatus
,o.CancelReasonDesc
,o.OriginationDate
,o.Completed
,DATEDIFF(d,o.OriginationDate,GETDATE())
as Total
FROM
hgmclent AS c
LEFT
OUTER
JOIN QLHPM_Order_Summary
AS o
ON
c.client_no
= o.ClientNumber
WHERE
o.Ordernumber
IS
NOT
NULL
GROUP
BY c.client_no
,c.forename
,c.surname
,c.tel_no1
,c.tel_no2
,c.tel_no3
,o.ordernumber
,o.propertyidentifier
,o.contractorlongname
,o.OrderStatus
,o.CancelReasonDesc
,o.OriginationDate
,o.Completed
Currently this produces the following data from which I have hidden sensitive information. What I need to show for client_no 1 is repair order 6353 which was reported on 2015-01-06 00:00:00.000 being the most recent of 12 orders for this client,
Client No2 only has one order so this will be shown
Client No3 should only show order number 6842 reported on 2015-01-19 00:00:00.000
and so on.
Can anyone help with this
Thanks
JohnI think he needs to return the data for the latest OriginationDate, so ORDER BY o.Completed DESC should be changed to
ORDER BY o.OriginationDate DESC
Row_number() Over(Partition
by c.client_no Order
by o.OriginationDate
DESC ) rn
A Fan of SSIS, SSRS and SSAS -
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) -
Remove Duplicate Rows in Numbers 09
Is there a way to remove duplicate rows in Numbers 09? For example I have 2 Tables and the values of Column A are mainly the same, but there are definitely a few dozen unique values in 1 table which are not in table 2 and visa versa. I'd like to make a new table with a column A with all of the values, but with duplicates removed so that I can then compare the values of a different column based on the value of Column A for each table.
I copied tabeau 1 and tableau 2 in tableau 3 then in cell E2 of tableau 3 I entered the formula:
=COUNTIF($A$1:$A1,"="&A)
Using fillDown, I filled the column E
I get 0 if the cell a is unique
I get 1 (or higher) if the cell is available several times.
Sort upon column E
delete the rows whose cell E is not 0.
Yvan KOENIG (VALLAURIS, France.) samedi 22 août 2009 11:08:15 -
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); -
Deleting duplicate rows based on three columns in Oracle 8i
Hi all,
The database we use is Oracle 8i.
The query below raises the too_many_rows exception when I launch an application. So I want to delete the duplicated rows :
select polarisation_1, polarisation_2
into v_pol1_tech, v_pol2_tech
from v_cfh_lien_element
where nom_lien = p_nom_lien
AND num_canal_1 = p_num_canal_1
AND freq_emise_1 = p_freq_emise_1;
Notice that with many possible values of the parameters p_nom_lien, p_num_canal_1 and p_freq_emise_1 then the exception is raised.
So how to delete generally the duplicated rows based on the three columns "nom_lien" , "num_canal_1" and "freq_emise_1" ?
Thank you very much indeed.Check the other thread with same question deleting duplicate rows based on three columns in Oracle 8i
-
How to suppress a row based on current date - at query level?
In an Bex query report i have suppress rows based on current date.
There is no current date available in query.
there is a date field in the query.
If by chance the date in that field is lesser than current date, I have to suppress that row.
How can this be achieved?What is the code ofr creating a variable to get values >= to current date?
I have implemented the following code which is not working.
data L_S_range like line of E_T_range[].
CLEAR L_S_RANGE.
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'GE'.
L_S_RANGE-LOW = SY-DATUM.
APPEND L_S_RANGE TO E_T_RANGE[].
Actually i have written in class, which will be inherited in superclass.
Edited by: akshara20 on Feb 2, 2011 1:21 PM -
Cursor and Update rows based on value/date
SQL Server 2012
Microsoft SQL Server Management Studio
11.0.3128.0
Microsoft Analysis Services Client Tools
11.0.3128.0
Microsoft Data Access Components (MDAC)
6.1.7601.17514
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer
9.11.9600.16518
Microsoft .NET Framework
4.0.30319.18408
Operating System
6.1.7601
The objective of this is to test the Cursor and use it on a production environment after this is fixed. What I would like to do is update rows in a column i duplicated originally called 'HiredDate' from AdventureWorks2012 HumanResources.Employee table. I
made a duplicate column called 'DateToChange' and would like to change it based on a date I have picked, which returns normally 2 results (i.e. date is '04/07/2003'). The code runs but will not change both dates. It did run however with an error but changed
only 1 of the 2 rows because it said ['nothing available in next fetch'].
The code to add the columns and perform the query to get the results I am running this against:
-- ADD column 'DateToChange'
ALTER TABLE [HumanResources].[Employee] ADD DateToChange Date NOT NULL;
-- Copy 'HireDate' data to 'DateToChange'
UPDATE HumanResources.Employee SET DateToChange = HireDate;
-- Change 'DateToChange' to NOT NULL
ALTER TABLE [HumanResources].[Employee] ALTER COLUMN DateToChange Date NOT NULL;
SELECT BusinessEntityID,HireDate, CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
FROM HumanResources.Employee
WHERE [DateToChange] = '04/07/2003';
Code:
USE AdventureWorks2012;
GO
-- Holds output of the CURSOR
DECLARE @EmployeeID INT
DECLARE @HiredDate DATETIME
DECLARE @HiredModified DATETIME
DECLARE @ChangeDateTo DATETIME
--Declare cursor
-- SCROLL CURSOR ALLOWS "for extra options" to pul multiple records: i.e. PRIOR, ABSOLUTE ##, RELATIVE ##
DECLARE TestCursor CURSOR SCROLL FOR
-- SELECT statement of what records going to be used by CURSOR
-- Assign the query to the cursor.
SELECT /*HumanResources.Employee.BusinessEntityID, HumanResources.Employee.HireDate,*/ CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
FROM HumanResources.Employee
WHERE DateToChange = '01/01/1901'
/*ORDER BY HireDate DESC*/ FOR UPDATE OF [DateToChange];
-- Initiate CURSOR and load records
OPEN TestCursor
-- Get first row from query
FETCH NEXT FROM TestCursor
INTO @HiredModified
-- Logic to tell the Cursor while "@@FETCH_STATUS" 0 the cursor has successfully fetched the next record.
WHILE (@@FETCH_STATUS = 0 AND @@CURSOR_ROWS = -1)
BEGIN
FETCH NEXT FROM TestCursor
IF (@HiredModified = '04/07/2003')/*05/18/2006*/
-- Sets @HiredModifiedDate data to use for the change
SELECT @ChangeDateTo = '01/01/1901'
UPDATE HumanResources.Employee
SET [DateToChange] = @ChangeDateTo --'01/01/1901'
FROM HumanResources.Employee
WHERE CURRENT OF TestCursor;
END
-- CLOSE CURSOR
CLOSE TestCursor;
-- Remove any references held by cursor
DEALLOCATE TestCursor;
GO
This query is run successfully but it does not produce the desired results to change the dates
04/07/2003 to 01/01/1901.
I would like the query to essentially be able to run the initial select statement, and then update and iterate through the returned results while replacing the necessary column in each row.
I am also open to changes or a different design all together.
For this query I need:
1. To narrow the initial set of information
2. Check if the information returned, in particular a date, is before [i.e. this current month minus 12 months or
12 months before current month]
3. Next replace the dates with the needed date
[Haven't written this out yet but it will need to be done]
4. After all this is done I will then need to update a column on each row:
if the 'date' is within 12 months to 12 months from the date checked
NOTE: I am new to TSQL and have only been doing this for a few days, but I will understand or read up on what is explained if given enough information. Thank you in advance for anyone who may be able to help.The first thing you need to do is forget about cursors. Those are rarely needed. Instead you need to learn the basics of the tsql language and how to work with data in sets. For starters, your looping logic is incorrect. You open
the cursur and immediately fetch the first row. You enter the loop and the first thing in the loop does what? Fetches another row. That means you have "lost" the values from the first row fetched. You also do not test the success of
that fetch but immediately try to use the fetched value. In addition, your cursor includes the condition "DateToChange = '01/01/1901' " - by extension you only select rows where HireDate is Jan 1 1901. So the value fetched into @HiredModified will
never be anything different - it will always be Jan 1 1901. The IF logic inside your loop will always evaluate to FALSE.
But forget all that. In words, tell us what you are trying to do. It seems that you intend to add a new column to a table - one that is not null (ultimately) and is set to a particular value based on some criteria. Since you intend the
column to be not null, it is simpler to just add the column as not null with a default. Because you are adding the column, the assumption is that you need to set the appropriate value for EVERY row in the table so the actual default value can be anything.
Given the bogosity of the 1/1/1901 value, why not use this as your default and then set the column based on the Hiredate afterwards. Simply follow the alter table statement with an update statement. I don't really understand what your logic
or goal is, but perhaps that will come with a better description. In short:
alter table xxx add DateToChange date default '19010101'
update xxx set DateToChange = HireDate where [some unclear condition]
Lastly, you should consider wrapping everything you do in a transaction so that you recover from any errors. In a production system, you should consider making a backup immediately before you do anything - strongly consider and have a good reason not
to do so if that is your choice (and have a recovery plan just in case). -
I have two tables MEMBER_ADRESS and MEMBER_ORDER. The MEMBER_ADRESS has duplicate rows in it based on MEMBER_ID and MATCH_VALUE. These duplicate ADDRESS_IDs were used in MEMBER_ORDER. I need to remove the duplicates from MEMBER_ADRESS making sure I keep the one with PRIMARY_FLAG = ‘Y’ and update MEMBER_ORDER.ADDRESS_ID to the MEMBER_ADRESS.ADDRESS_ID that I kept.
I am on 11gR1
Thanks for the help.
CREATE TABLE MEMBER_ADRESS
ADDRESS_ID NUMBER,
MEMBER_ID NUMBER,
ADDRESS_1 VARCHAR2(30 BYTE),
ADDRESS_2 VARCHAR2(30 BYTE),
CITY VARCHAR2(25 BYTE),
STATE VARCHAR2(2 BYTE),
ZIPCODE VARCHAR2(10 BYTE),
CREATION_DATE DATE,
LAST_UPDATE_DATE DATE,
PRIMARY_FLAG CHAR(1 BYTE),
ADDITIONAL_COMPANY_INFO VARCHAR2(40 BYTE),
MATCH_VALUE NUMBER(38) GENERATED ALWAYS AS (TO_NUMBER( REGEXP_REPLACE ("ADDITIONAL_COMPANY_INFO"||"ADDRESS_1"||"ADDRESS_2"||"CITY"||"STATE"||"ZIPCODE",'[^[:digit:]]')))
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(200, 30, '11 Hourse Rd.',
'58754', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:10', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 1158754);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(230, 12, '101 Banks St',
'58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:35:42', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(232, 12, '101 Banks Street',
'58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:41:15', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(228, 12, '101 Banks St.',
'58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:38:19', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(221, 25, '881 Green Road',
'58887', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:18', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 88158887);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(278, 28, '2811 Brown St.',
'58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:36:11', 'MM/DD/YYYY HH24:MI:SS'), 'N', 281158224);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(280, 28, '2811 Brown Street',
'58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:45:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 281158224);
Insert into MEMBER_ADRESS
(ADDRESS_ID, MEMBER_ID, ADDRESS_1, ADDRESS_2, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
Values
(300, 12, '3421 West North Street', 'x',
'58488', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:42:04', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 342158488);
COMMIT;
CREATE TABLE MEMBER_ORDER
ORDER_ID NUMBER,
ADDRESS_ID NUMBER,
MEMBER_ID NUMBER
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(3, 200, 30);
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(4, 230, 12);
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(5, 228, 12);
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(6, 278, 28);
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(8, 278, 28);
Insert into MEMBER_ORDER
(ORDER_ID, ADDRESS_ID, MEMBER_ID)
Values
(10, 230, 12);
COMMIT;Hi John;
Sorry I missed your post. Yes sorry about the flag. Please take a look as these before and after sets. I hope this helps. I should have posted this in the begining.
MEMBER_ORDER (BEFORE)
ORDER_ID ADDRESS_ID MEMEBER_ID
4 228 12
10 230 12
5 230 12
11 232 12
12 300 12
8 278 28
6 278 28
3 200 30
MEMBER_ORDER (AFTER)
ORDER_ID ADDRESS_ID MEMEBER_ID
4 232 12
10 232 12
5 232 12
11 232 12
12 300 12
8 280 28
6 280 28
3 200 30
MEMBER_ADDRESS (BEFORE)
ADDRESS_ID MEMBER_ID ADDRESS_1 CREATION_DATE LAST_UPDATE_DATE PRIMARY_FLAG MATCH_VALUE
228 12 101 Banks St. 8/11/2000 10:56:25 AM 8/12/2005 10:38:19 AM N 10158487
230 12 101 Banks St 8/11/2000 10:56:25 AM 8/12/2006 10:35:42 AM N 10158487
232 12 101 Banks Street 8/11/2000 10:56:25 AM 8/12/2007 10:41:15 AM N 10158487
300 12 3421 West North Street 8/11/2000 10:56:25 AM 8/12/2011 10:42:04 AM Y 342158488
221 25 881 Green Road 8/11/2000 10:56:25 AM 8/12/2011 10:34:18 AM Y 88158887
278 28 2811 Brown St. 8/11/2000 10:56:25 AM 8/12/2006 10:36:11 AM N 281158224
280 28 2811 Brown Street 8/11/2000 10:56:25 AM 8/12/2011 10:45:00 AM Y 281158224
200 30 11 Hourse Rd. 8/11/2000 10:56:25 AM 8/12/2005 10:34:10 AM Y 1158754
MEMBER_ADDRESS (AFTER)
ADDRESS_ID MEMBER_ID ADDRESS_1 CREATION_DATE LAST_UPDATE_DATE PRIMARY_FLAG MATCH_VALUE
232 12 101 Banks Street 8/11/2000 10:56:25 AM 8/12/2007 10:41:15 AM N 10158487
300 12 3421 West North Street 8/11/2000 10:56:25 AM 8/12/2011 10:42:04 AM Y 342158488
221 25 881 Green Road 8/11/2000 10:56:25 AM 8/12/2011 10:34:18 AM Y 88158887
280 28 2811 Brown Street 8/11/2000 10:56:25 AM 8/12/2011 10:45:00 AM Y 281158224
200 30 11 Hourse Rd. 8/11/2000 10:56:25 AM 8/12/2005 10:34:10 AM Y 1158754 -
Delete duplicate rows -- based on 4 columns -- how?
I asked this question on how to delete duplicates recently and received this suggestion which works well -- except --
With CTE AS
SELECT *, ROW_NUMBER() OVER (Partition by fld1 order by fld1) RowNum
FROM #tmpA
DELETE From CTE
WHERE RowNum > 1
-- the actual table I need to delete duplicate rows on is based on 4 columns. The following table contains 14,462 rows of which 14,348 are distinct -- based on the following 4 colums. Below is an image of a sample of the data contained in the
table for my question and to the right of that data is the column structures (data types). Is it possible to do something like the above example suggestion with the table in the image below? How to do that? I need to delete rows so that 14462
goes down to 14348. If I only reference one column for the delete -- this would delete like 7000+ rows. I only need to remove 114 rows.
Rich PAdd the other 3 columns to the partition.
Jason Long -
Macro to remove duplicate rows between two worksheets
Hi
We have a master file which multiple users access through 'sharepoint'.
The 'sharepoint' service had an issue, and this master file (which two users spend a day each working on) has not updated.
We are left with two variations of the same master file, and need to merge them together - allowing adjustments made by both users to stand. The master has 45 columns, and the copies have between 20916 and 21034 rows inc header.
As I have basic capabilities with Macro's, would someone be able to advise?
Kind regards
MetakioRe: Merging two files
One way...
In a new workbook, paste copies of the two sets of data onto a single sheet with one set of data directly below the other.
Use Excel's Remove Duplicates feature to remove the duplicate rows.
Jim Cone
Portland, Oregon USA
free & commercial excel programs
https://jumpshare.com/b/O5FC6LaBQ6U3UPXjOmX2 -
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) -
If any duplicate rows exist in the table I wanna delete the oldest rows between 2007-01-01 and 2007-12-31. The latest row I wanna keep. Is this the right way to do this:
Delete from tblSalesInfo
Where ROWID NOT IN (SELECT Max(ROWID) FROM tblSalesInfo GROUP BY salesorder, salesorder_item, orderquantity, line)
And rec_date between to_date('2007-01-01','yyyy-mm-dd') And to_date('2007-12-31','yyyy-mm-dd')
And comments Is Null;Ok, perhaps i should have explained what i sent you does.
The inner most select partitions out the data into "groups" much like your group by clause does. It assigns a number to each row 1, 2, 3, ..... N over that partition, when a new partition comes about it starts ordering the data again.
for example.....
ME_XE?create table test (column1 varchar2(10), column2 varchar2(20));
Table created.
Elapsed: 00:00:00.04
ME_XE?insert into test values ('row1', 'not a dup yet');
1 row created.
Elapsed: 00:00:00.00
ME_XE?insert into test values ('row1', 'dup');
1 row created.
Elapsed: 00:00:00.00
ME_XE?insert into test values ('row2', 'all alone');
1 row created.
Elapsed: 00:00:00.00
ME_XE?
ME_XE?select row_number() over (partition by column1 order by column2 asc) as THE_ROWNUMBER, column1, column2
2 from test;
THE_ROWNUMBER COLUMN1 COLUMN2
1 row1 dup
2 row1 not a dup yet
1 row2 all alone
3 rows selected.
Elapsed: 00:00:00.01So what you want to do in order to identify duplicates is say
1) assign a row number to each set of values that i define to be a duplicate
2) keep all the rowids that are duplicates
3) delete from the table where the ROWID matches all the kept rowids from step 2.
make more sense? -
How not show duplicate rows based on one field
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Hello
I have a query that looks for certain scripts that did not run on a particular day compared to what ran the same day a week ago. We want to include the start_datetime and end_datetime but when I add it to the select statement it brings up all instances of the jobs that run multiple times during the day. Is there a way to exclude the extra rows based on the script_name field?
SELECT instances.script_name,
instances.instance_name,
REGEXP_REPLACE(master.description,
chr(49814), -- em-dash
'-') description
--instances.start_datetime
FROM xxcar.xxcar_abat_instances Instances,
xxcar.xxcar_abatch_master Master
WHERE 1 = 1
AND TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
AND Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
MINUS
SELECT script_name,
instance_name,
NULL
--NULL
FROM xxcar.xxcar_abat_instances
WHERE 1 = 1
AND TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))MINUS does a set operation - removing rows from the first set that exactly match the second set.
When you add columns to the first set, you want a more restricted filtering - try a multi-column NOT IN:
To remove multiple runs, group and get min/max
SELECT instances.script_name,
instances.instance_name,
REGEXP_REPLACE(master.description,
chr(49814), -- em-dash
'-') description,
min(instances.start_datetime) start_datetime,
min(instances.end_datetime) end_datetime
FROM xxcar.xxcar_abat_instances Instances,
xxcar.xxcar_abatch_master Master
WHERE 1 = 1
AND TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
AND Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
AND (script_name, instance_name) NOT IN
( SELECT script_name,
instance_name
FROM xxcar.xxcar_abat_instances
WHERE 1 = 1
AND TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))
group by instances.script_name, instances.instance_name, master.descriptionYou didn't give table definitions, and the query has schemas in it, so I didn't test it.
regards,
David -
Selecting duplicate rows based on a combination of columns as key
Hi ,
I have a table with 5 columns.
Code ID S_DATE E_DATE Name
1 23 01012001 null ABC
1 09 01012001 null XYZ
2 81 04022007 null TVU
1 43 03092008 null XXX
Now, I need write a select query to fetch the duplicate rows from the above table having the combination of (Code, S_DATE,E_DATE) as the key.
So from the above example, I need to get Row1 and Row2 as output (but not Row3 as it has a different S_DATE)
Thanks in advance for your suggestions.
Thanks
Edited by: thotaramesh on Mar 9, 2009 4:54 PMOn XE;
WITH sample_data AS (
SELECT 1 code,23 ID, '01012001' s_date, null e_date, 'ABC' NAME FROM dual UNION ALL
SELECT 1, 09, '01012001', null, 'XYZ' FROM dual UNION ALL
SELECT 2, 81, '04022007', null, 'TVU' FROM dual UNION ALL
SELECT 1, 43, '03092008', null, 'XXX' FROM dual)
SELECT code, ID, s_date, e_date, NAME
FROM (
SELECT
sample_data.*,
COUNT(*) over (PARTITION BY code, s_date, e_date) dups
FROM sample_data)
WHERE dups > 1;
CODE ID S_DATE E_DATE NAME
1 23 01012001 ABC
1 9 01012001 XYZ
Maybe you are looking for
-
Error message when dragging a tv show from iTunes to my nano...
I get this message when trying to drag in a tv show from iTunes to ny nano... "Pilot (tv show is called 10 things i hate about you) was not copied to the iPod because it cannot be played on this iPod." This tv show was on the nano at some point. I ha
-
How do I move photo's to and from iphone.
L.S. Hello everybody last time when i needed help i got some good response so I thought lets try that again. It seems(looking at other fora) I am Not the only person with this problem but so far I havn't found the solution. Here is my problem. When I
-
Images not displaying in new java plugin
Hey everyone.. In the old plugin my java applet worked fine in a web browser. Everything displayed okay.. Now the images don't display at all in the new plugin. What gives!?
-
SkyGo does not remember last watched position
Dear Sky, Along with my other gripe of SkyGo now wanting to access wifi for already downloaded content, I have another issue. When a programme is paused and the iPad locks after a screen timeout, or you shut the app for any other reason, it no longer
-
HT1725 my ipad mini I have 30 tv episodes that started to download but i stopped
I realized i didn't have the space for 30 tv episodes and the movies i have on my ipad mini so they stopped as it ran out of space, now whenever I want to download anything I have the 30 episodes sitting there with a note to tap to retry, but it does