find different or missing rows in one table [message #619983] |
Sun, 27 July 2014 06:58 |
|
forumwurm
Messages: 12 Registered: March 2014
|
Junior Member |
|
|
Hi all
I'm new to Oracle and SQL statements. Could somebody please tell me how I can achieve the following:
I have a table in Oracle and should find the rows which are different between Version OLD and Version New (which is a field as well)
Version Field1 Field2 Field3 Field4 Value
OLD Hypo abcd 1234 something 1
NEW Hypo abcd 1234 something 1
OLD Hypo abcd 1234 something 2
NEW Hypo abcd 1234 something 2
OLD Hypo abcd 1234 something 3
NEW Hypo abcd 1234 something 3
OLD Hypo abcd 1234 something 4
NEW Hypo abcd 1234 something 4
OLD Hypo abcd 1234 something 5
NEW Hypo abcd 1234 something 5div
OLD Hypo abcd 1234 something 6
NEW Hypo abcd 1234 something 6
OLD Hypo abcd 1234 something 7
NEW Hypo abcd 1234 something 7
OLD Hypo abcd 1234 something 8
In this example I should find two lines:
- 5div is different
- and value 8 is missing in the NEW version.
which SQL statement will bring me this output?
Many thanks for links, tips, or a statement
FW
|
|
|
|
Re: find different or missing rows in one table [message #619991 is a reply to message #619983] |
Sun, 27 July 2014 07:46 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
forumwurm wrote on Sun, 27 July 2014 17:28
In this example I should find two lines:
- 5div is different
- and value 8 is missing in the NEW version.
which SQL statement will bring me this output?
You need a set operator, MINUS.
Something like,
WITH old_ver
AS (SELECT *
FROM table
WHERE version = 'OLD'),
new_ver
AS (SELECT *
FROM table
WHERE version = 'NEW')
SELECT *
FROM new_ver
MINUS
SELECT *
FROM old_ver
Note : The above code is not tested, it's just an example.
|
|
|
Re: find different or missing rows in one table [message #619994 is a reply to message #619991] |
Sun, 27 July 2014 07:55 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I was thinking ofselect max(version),field1,field2,field3,field4,value,count(*) from whatever
group by field1,field2,field3,field4,value having count(*)=1;
I'm sure there are other solutions too.
|
|
|
|
|
|
|
Re: find different or missing rows in one table [message #620025 is a reply to message #620013] |
Mon, 28 July 2014 00:07 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote:@ Lalit, this did not give me the result I'm looking for.
We have not your tables and data.
If you want specific query valid for your case you must post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data.
|
|
|