How to fetch deleted enteries by comparing two tables
Hi
I have two tables:
1. CrawlOldXml: It contains two columns "ProductName" and "ProductImageUrl". In this table, I have inserted old records like
Product1, ProductImage1.jpg
Product2, ProductImage2.jpg
Product3, ProductImage3.jpg
2. CrawlNewXml: It contains two columns "ProductName" and "ProductImageUrl". In this table, I insert new records like
Product1, ProductImage1.jpg
Product2, ProductImage3.jpg
Product4, ProductImage4.jpg
Now as we can see that in CrawlNewXml table Product2 has an updated Image url i.e. ProductImageUrl3.jpg. And also Product3 entry is removed form the CrawlNewXml table.
I want a query which could give the resulted rows which are deleted i.e. removed from table CrawlNewXml.
For example if i run a query on CrawlNewXml and CrawlOldXml then its result should be
Product3, ProductImage3.jpg
Hi,
You said, by using the first query, you are getting the updated records and using the second query, you are getting the updated records + deleted records. Now, you want only the deleted records. So, your second query MINUS first query would give you deleted records?
I.e
For getting the inserted/updated records :
Select ProductName, productImageUrl
From
Select 'Table A' as TableName, A.Productname. A.ProductImageUrl From CrawlNewXml as A
Union All
Select 'Table B' as TableName, B.Productname. B.ProductImageUrl From CrawlOldXml as B
)temp
Group By ProductName, ProductImageUrl
Having count(*)=1)t
where t.tableName='Table A' Order By ProductName,ProductImageUrlFor getting the Deleted Records :
Select ProductName, productImageUrl
From
Select 'Table A' as TableName, A.Productname. A.ProductImageUrl From CrawlNewXml as A
Union All
Select 'Table B' as TableName, B.Productname. B.ProductImageUrl From CrawlOldXml as B
)temp
Group By ProductName, ProductImageUrl
Having count(*)=1)t
where t.tableName='Table B' Order By ProductName,ProductImageUrl
MINUS
Select ProductName, productImageUrl
From
Select 'Table A' as TableName, A.Productname. A.ProductImageUrl From CrawlNewXml as A
Union All
Select 'Table B' as TableName, B.Productname. B.ProductImageUrl From CrawlOldXml as B
)temp
Group By ProductName, ProductImageUrl
Having count(*)=1)t
where t.tableName='Table A' Order By ProductName,ProductImageUrl-Arun
P.S : You seem to have a table without a primary key. Tables with this kind of design would yield you to this kind of difficulties ;-). Time to refactor your database design.
Similar Messages
-
How to compare two tables in SSIS?
I am creating an SSIS package that will compare two tables and then insert data in another table.
Which tool shall I use for that? I tried to use "Conditional Split" but it looks like it only takes one table as input and not two.
These are my tables:
TABLE1
ID
Status
TABLE2
ID
Status
TABLE3
ID
STatus
I want to compare STATUS field in both tables. If Status in TABLE1 is "Pending" and in TABLE2 is "Open" then insert this record in TABLE3.You can use MERGE command , Sorry cannot test it right now.
MERGE INTO tbl3
USING (SELECT tbl2.ID, tbl2.status,tbl1.status as st1 FROM tbl1 JOIN tbl2 ON tbl1.ID=tbl2.ID) AS t ON T.ID=tbl3.ID
AND t.status='OPEN' AND t.st1='pending'
WHEN NOT MATCHED
INSERT (status) VALUES (t.status)
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
how to compare two tables between two systems ?
hi sravan, u can go to t/c OY19 to compare the two tables.
Choose Manual selection
Enter the name of the table that you want to compare
Choose Execute
in the next screen you have to give the description and RFC connection name which will make the link between two clients.
Regards...
Arun.
Reward points if useful. -
How to find the structural difference between two tables
Hi all,
How to find the structural difference between two tables .
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
Thanks,
P Prakashyou could try something similar to this, for each table pair that you want to compare:
SELECT 'TABLE_A has these columns that are not in TABLE_B', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
) DIFF
UNION
SELECT 'TABLE_B has these columns that are not in TABLE_A', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
) DIFF;that's assuming, column_name, data_type and data_length are all you want to compare on. -
hi all,
i am using db10g.
my task is to compare two table's data for example
table1 is having
col1 col2 col3
a b c
e f g
table2 is
col4 col5 col6
a e c
e f g
so i have to compare col1 first record and col4 first record.
in otherwords first table first column first item with second table first table first value and so on.
for ex: a= a
b= e
c= c etc
how can i acheive this?
both are database tables.
i cannot use minus function because data types are different for the corresponding column
how can i compare it?
Thanks..
Edited by: user13329002 on Jan 13, 2011 1:09 AMHi,
Try this
select
case
when a.col1 = b.col1 then 'EQUAL' else 'NOT EQUAL' end column1,
case
when a.col2 = b.col2 then 'EQUAL' else 'NOT EQUAL' end column2,
case
when a.col3 = b.col3 then 'EQUAL' else 'NOT EQUAL' end column3
from (select col1,col2,col3,rownum rn from table1) a,
(select col1,col2,col3,rownum rn from table2) b where a.rn = b.rn Try to see how you order the rows of the two tables.
cheers
VT -
Comparing Two tables with 300k records and update one table
Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.
Why are you trying to use PL/SQL tables? If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL. -
HI,
How to compare two tables in ODI.I want to extract UNMATCHED data in the two tables without using procedures,views.Hi,
these tables has the exactly same ddl or the comparacion will be based on PK (or UK)? -
How can we delete wild card entry from table
how can we delete wild card entry from table
i want adjust the seeting for order type print out form
like in 0id2 i have specified ordertupe nad print form in pm module
but in oid3 fro palnner group if i make star it is not taking specific defiend fieldHi....
Follow these steps....
1. Goto se16 and enter ur table name.. press F7 you can get selection screen now press F8...
2. Click one perticuler record that u want to delete.. and press Change icon in App'toll bar...
3. enter ?H at command field and again press enter...
4. switch into classical debugger...
5. write CODE at field ... it will gives EDIT as value...
6. Change that EDIT into SHOW and press pencel icon just beside the SHOW...
7. Now press F8...
8. you can get delete option over there...
Thanks,
Naveen.I -
BUG? BRIDGE statement to compare two tables
Hello,
I tried to compare two tables in different dbs and remembered a post about Cross Connectin Queries
http://barrymcgillin.blogspot.com/2010/11/cross-connection-queries.html
BRIDGE temparb AS "EB05 01"
(SELECT * FROM arb)
(SELECT * FROM temparb
MINUS
SELECT * FROM arb
UNION ALL
(SELECT * FROM arb
MINUS
SELECT * FROM temparb
);I would expect to get the differences between the table arb in my current schema and the table arb alias temparb in the other db. Yet it seems, that in this case only the table in my current schema is read.
I materialize the BRIDGE table with
BRIDGE temparb AS "EB05 01"
(SELECT * FROM arb)and select the value I know to be only in the remote schema
SELECT id FROM temparb WHERE id = 2562;
SELECT id FROM arb WHERE id = 2562;Both times I get no result. I even tried to use aliases on the table, same result. Tested in 3.0 and 3.1 EA3.
Has anyone tried this before?
Regards
MarcusHi Marcus,
Have you tried it without the double quotes around the connection name?
I have a connection called
system_local
which I run the following command in
drop table testbridge_remote;
drop table testdbrige;
create table testbridge(col1 int);
insert into testbridge values (1);
insert into testbridge values (2);
insert into testbridge values (3);
commit;
I have a connection called
Connection Name With Space
which I run the following in
drop table testdbrige;
create table testbridge(col1 int);
insert into testbridge values (4);
insert into testbridge values (5);
insert into testbridge values (3);
commit;
Then in the system_local connection/worksheet I can run the following statement
BRIDGE testbridge_remote as Connection Name With Space(select * from testbridge)
+(SELECT * FROM testbridge_remote+
MINUS
SELECT * FROM testbridge
+)+
UNION ALL
+(SELECT * FROM testbridge+
MINUS
SELECT * FROM testbridge_remote
+);+
It works ok.
Returning rows in the remote table not in the local table , and rows in the local table not in the remote table .
Regards,
Dermot
SQL Developer Team. -
Compare two tables and log the difference
Hi,
I want to compare two tables and log the difference in new table with the fields as (old value,new value, column name). The column name should be the changes value columnCan you show an example?
SELECT Foo.*, Bar.*
FROM Foo
FULL OUTER JOIN
Bar
ON Foo.c1 = Bar.c1
AND Foo.c2 = Bar.c2
AND Foo.cn = Bar.cn
WHERE Foo.key IS NULL
OR Bar.key IS NULL;
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How the data is entered in the customized table
Hi,
In implemenation scenario when we create generic extraction , how the data is entered
in the customized table if it is huge data ( around 5000 records)
Regards,
VivekHi Vivek,
Follow bellow steps:
1.Goto RSO2.
Choose Datasource from bellow of Three
a). Transaction Data
b). Master data Attributes
c). Master data Text
2.Specify Application component(SD/MM..)
3.There are three extraction methods to fill datasource.
4.Select extraction method extracts the data from a transparent table or database view.
5.Select Extraction from View, then we have to create the View.
a).Specify the view name.
b).Choose the view type (Database view) from bellow mentioned views.
i). Database view.
ii). Projection view.
iii).Maintainance view.
iv). Help view.
6. Specify Tables and Join Conditions and define view fields.
7. Assign View to Datasource
8. Once you specify view in Data source, the extract structure will generate.
9. you can check the data in RSA3.
Regards,
Suman -
How can we delete a line from the table control .
hi all
how can we delete a line from the table control .
situation is.
created table control in se51 which will display the data of a table.
how could i select a line from the table control ?
how could i delete the selected lines form the table.
thanks in advanceChange the Table Control attributes such that user can only select a single record(row).
<u>Tip to delete a selected record</u>
1) write a module 'Mark' in the PAI as below
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
LOOP WITH CONTROL table_view.
MODULE read_table_control.
FIELD flag MODULE mark ON INPUT.
ENDLOOP.
MODULE user_command_0100.
2) Module Mark is below.
MODULE mark INPUT.
CHECK flag = 'X'.
x = table_view-top_line + sy-stepl - 1.
Delete itab INDEX x.
ENDMODULE. " mark INPUT
Table_view is the TableControl Name.
'flag' is of type char(1) available in the Internal table which was assigned to the select option in the table control.
<u>award if uesful</u>
Regards,
Sudheer -
How to fetch data where reference with two values
Hello Gurus,
How to fetch data from database table with two values for reference. like
SELECT < FIELDS>
FROM <DB>
INTO TABLE TAB2
FOR ALL ENTRIES IN
TAB1
WHERE
FIELD1 = TAB1-FIELD1 AND
FIELD1 = TAB1-FIELD2.Hi,
If you want to get data for both fields then Instead of AND use OR
SELECT < FIELDS>
FROM <DB>
INTO TABLE TAB2
FOR ALL ENTRIES IN
TAB1
WHERE
FIELD1 = TAB1-FIELD1 OR
FIELD1 = TAB1-FIELD2.
Or if you want that only common data for both fields should be fetched then create new internal table. Append data of both fields into that table. Sort new table and do delete adjust duplicate. Now use new internal table in your select query.
Let me know if this helps.
Regards,
Jigar Thakkar. -
How do I delete one of the two itunes accounts on my iPhone?
I used to sync my phone on my daughter's computer, and somehow both accounts (mine and hers) got on my iPhone. When I try to download or update apps, it either asks for my password or my daughter's, and I can't update my apps anymore because I do not have the password to her account. How do I delete her account off of my iPhone? I've looked everywhere online and can't find the answer. Also, I'm now syncing on a different computer without her account, but it still hasn't deleted. PLEASE help
All apps - all paid and free apps include DRM protection that is tied to the iTunes that was used to download the apps. This means you have apps on your iPhone that were downloaded with your daughter's iTunes account. Apps cannot be transferred or merged with another iTunes account.
Delete the apps from your iPhone that were downloaded with your daughter's iTunes account to prevent being prompted for the account's password when there are app updates for the apps downloaded with the account. An iTunes account cannot be deleted. -
How to compare two tables data...need sql report or utility to find differe
Hi,
We have a requirement where we are asked to find data differences between two tables and one of the tables reside on remote database. The database version is same ( 10g ) and datatypes for the tables are similar.
The client is looking for a sql report or kind of utility to display the data differences for each column ( if possible count differences ) with some meaningful error messages.
Could anyone let me know the best possible way of doing it..?
Thanks
HitarthHi,
I found something for tables comparison but getting one error...can you check this please and let me know what is wrong
Here is the function:
CREATE OR REPLACE FUNCTION compare_query_results (
p_query1 IN VARCHAR2
, p_query2 IN VARCHAR2
, p_raise_error_if_not_equal IN BOOLEAN DEFAULT FALSE
, p_raise_error_if_no_rows IN BOOLEAN DEFAULT FALSE
RETURN NUMBER
IS
-- Constants
c_query_results_equal CONSTANT PLS_INTEGER := 0;
c_query_results_not_equal CONSTANT PLS_INTEGER := 1;
oracr CONSTANT VARCHAR2 (1) := CHR (10);
-- Variable Declaration
v_sql_stmt VARCHAR2 (32767);
v_record_count PLS_INTEGER;
v_return_code PLS_INTEGER;
v_record DUAL.dummy%TYPE;
v_result_set_has_rows BOOLEAN;
-- Ref Cursors
v_cursor sys_refcursor;
-- Custom Defined-Exceptions
result_sets_do_not_match EXCEPTION;
query_returns_no_rows EXCEPTION;
BEGIN
-- Get the count of differing records between p_query1 and p_query2
dbms_output.put_line('Start-1');
v_sql_stmt :=
' (SELECT /*+ materialize */'
|| SUBSTR (p_query1, INSTR (UPPER (p_query1)
, 'SELECT'
, 1
, 1
) + 6)
|| ')
, (SELECT /*+ materialize */'
|| SUBSTR (p_query2, INSTR (UPPER (p_query2)
, 'SELECT'
, 1
, 1
) + 6)
|| ')
SELECT ''X''
FROM (
(SELECT * FROM test1 MINUS SELECT * FROM test2)
UNION ALL
(SELECT * FROM test2 MINUS SELECT * FROM test1)
dbms_output.put_line('Start-2');
OPEN v_cursor
FOR v_sql_stmt;
dbms_output.put_line('Start-3');
FETCH v_cursor
INTO v_record;
dbms_output.put_line('Start-4');
v_result_set_has_rows := v_cursor%FOUND;
dbms_output.put_line('Start-5');
CLOSE v_cursor;
dbms_output.put_line('Start-6');
-- If there are rows - the result sets do NOT match...
IF v_result_set_has_rows
THEN
v_return_code := c_query_results_not_equal;
IF p_raise_error_if_not_equal
THEN
RAISE result_sets_do_not_match;
END IF;
-- If there are no rows - the result sets do match...
ELSIF NOT v_result_set_has_rows
THEN
IF p_raise_error_if_no_rows
THEN
-- Check to make sure that the queries contain rows if desired...
v_sql_stmt := 'SELECT ''X''
FROM (' || oracr || p_query1 || oracr || ')';
OPEN v_cursor
FOR v_sql_stmt;
FETCH v_cursor
INTO v_record;
IF v_cursor%NOTFOUND
THEN
CLOSE v_cursor;
RAISE query_returns_no_rows;
END IF;
CLOSE v_cursor;
END IF;
v_return_code := c_query_results_equal;
END IF;
RETURN v_return_code;
EXCEPTION
WHEN result_sets_do_not_match
THEN
raise_application_error (-20101, 'The Queries'' result sets do NOT match. Error returned
as requested.');
WHEN query_returns_no_rows
THEN
raise_application_error (-20102, 'The Queries'' result sets match, however they contain no
rows. Error returned as requested.');
WHEN OTHERS
THEN
-- Raise the error
raise_application_error (-20103
, 'There is a syntax or semantical error in one or both queries
preventing comparison.'
|| oracr
|| 'Error Stack :'
|| oracr
|| DBMS_UTILITY.format_error_stack ()
|| oracr
|| 'Error_Backtrace:'
|| oracr
|| DBMS_UTILITY.format_error_backtrace ());
END compare_query_results;
I have created two tables ( test1 and test2 ) with few columns and with the same datatypes and executed the above function...I am getting error as folliowing:
DECLARE
ERROR at line 1:
ORA-20103: There is a syntax or semantical error in one or both queries
preventing comparison.
Error Stack :
ORA-00900: invalid SQL statement
Error_Backtrace:
ORA-06512: at "ORAOWNER.COMPARE_QUERY_RESULTS", line 53
ORA-06512: at "ORAOWNER.COMPARE_QUERY_RESULTS", line 121
ORA-06512: at line 12
Could someone please help me fixing this error..It would be really appreciated
Thanks
Hitarth
Maybe you are looking for
-
Hi QM Experts, IS it necessary to confirm operations in production CO11n after confirming the same in quality module? Thanks
-
Problem with ORA -03113 End of Communication Channel
Hello, Oracle Database 10g Release 10.2.0.1.0 - Production Windows Server 2003 Version V5.2 Service Pack 2 Im having this problem when executing an stored procedure that executes a SQL statement wich has uses db links... I get this end of communicati
-
All about a Transport! (ver y urgent)
Hi all, Can anyone help me knowing all the possible transaction codes helpful while doing or dealing with a transport. Any tables which reveal the effect of a transport , and is there a way to roll back the effect of a transport which has been
-
I have one pc in my office and one in my home. Office pc is running Windows XP and my home pc is on windows 98. Now i want to Access my office computer through my home computer. I have also installed (Remote Desktop Connection)(An XP facility) in Win
-
Hi All, I recently installed Microsoft Office 2008 in my MacBook, but the applications run pretty slow (only Office), specially PowerPoint. Any suggestions on how to improve the speed of those applications? Getting a new RAM memory perhaps? I install