Finding unmatched records between two tables
Hi,
Suppose there are two tables - A and B and they have a couple of common key fields. I want to select those records from A which do not have a matching record in B. What will be most efficient way to do that?
Thank you.
Hey,
Look at this link .......... i think this may help you a bit to achieve ur requirement
http://help.sap.com/saphelp_470/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
Comparing Internal Tables: -
Internal tables can be compared with the operands that are used to compare other data objects. The most important criteria for comparing the internal table are the number of lines they contain. The larger the number of lines, the larger it is for comparisons. If the both the internal tables have same number of lines, then they are compared line by line. The operands used for comparisons are LE, LT, GE, GT, EQ, NE.
Except for EQ, the comparison stops at the first pair of components that identifies the condition false.
Similar Messages
-
Need to find the Difference between two table
Hello ,
I have stucked in program as below scenario:-
I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
Example TableA
Col1 col2 col3 col4 col5.... col50
10 ABC 2001 EE 444 TT
40 XYZ 3002 RR 445 TT3
80 DEF 6005 YY 446 YY8
TableB
Col1 col2 col3 col4 col5.... col50
10 ABC 2001 EE 444 TT
40 XYZ 3002 RR 445 TT3
81 DEF 6005 Yu 447 YY8
I need to the out put like this :-
The Diffence between two table is
TableA.COL1=80 TableB.Col1=81, Different
TableA.Col4=YY TableB.col4=Yu,Different
TableA.Col5=446TableB.col5=447,Different
Please suggest me to write the pl/sql program for the same
thanx in advance
KKThanx friends for all your efforts
I have a sample code for the same,this will compare the two tables for single row in each table .
what r the modification needed for the multiple rows of values in the two tables??
Please suggest!!
CREATE OR REPLACE PROCEDURE test_compare
IS
TYPE t_col
IS
TABLE OF VARCHAR2 (30)
INDEX BY PLS_INTEGER;
l_col t_col;
j NUMBER := 0;
l_sql VARCHAR2 (2000);
col1 VARCHAR2 (30);
col2 VARCHAR2 (30);
val1 NUMBER;
val2 NUMBER;
status VARCHAR2 (30);
CURSOR c1
IS
SELECT column_id, column_name
FROM all_tab_columns
WHERE table_name = 'TEST1';
BEGIN
FOR i IN c1
LOOP
j := j + 1;
l_col (j) := i.column_name;
END LOOP;
FOR k IN 1 .. j
LOOP
l_sql :=
'SELECT '
|| ''''
|| l_col (k)
|| ''''
|| ', '
|| 'TEST2.'
|| l_col (k)
|| ', '
|| ''''
|| l_col (k)
|| ''''
|| ', '
|| 'TEST1.'
|| l_col (k )
|| ', '
|| 'DECODE(TEST2.'
|| l_col (k)
|| ' -TEST1.'
|| l_col (k)
|| ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
IF status = 'CHANGED'
THEN
DBMS_OUTPUT.put_line( 'TEST2.'
|| col1
|| '='
|| val1
|| ', TEST1.'
|| col2
|| '='
|| val2
|| ', '
|| status);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
END;
/ -
To find matching records across two tables
Hi folks,
I have a question regarding modifying the query. I am trying to compare the data between two tables, there are matching records in two tables, but are not in the same order. How to modify the query so that it finds the matching record between the two tables?
Here is my code
loop at itab_A.
read table itab_B with key
employeenumber = itab_zmgr_training-empid binary search.
if sy-subrc = 0.
Any thoughts?
Thanks,
Sk
Here I am getting the return value as '4'I have tried all that, but why is it that while reading a record from itab_B I see no record in the header line,
Let me paste the entire code of what I am trying to achieve.
data: itab_A like A occurs 0 with header line.
data: itab_B like B occurs 0 with header line.
some validation.....
loop at itab_A.
read table itab_B with key employee number = empid binary search.
if sy-subrc =0.
per form validation.
else.
perform validation.
endif.
endloop.
My observation: while reading recrod from itab_B the header line is clear, no record is read here hence sy-subrc = 0.
How can I correct this? Since it is not reading any record from itab_B no matching record is found.
Any thoughts would be really helpful.
Thanks,
Santhosh. -
How to find varience records in two tables
Hi,
i have two tables like emp1, emp2
data in emp1:
empname empid add
alasta 10 ca
mark 20 nw
chews 30 jp
data in emp2:
empname empid add
alasta 10 ca
mark 20 nw
chews 30 jp
burgess 45 ngm
if u observe the above two tables data you can easily identify there is repeated data/duplicated data in both tables.
as there any way find out using comparison same records in two tables..........
if i write a query then i can easily understand the same data is existed in two tables
Thanks in advance....>
as there any way find out using comparison same records in two tables..........
>
>
if i write a query then i can easily understand the same data is existed in two tables
>
So, what is your problem now?
You can join both the tables using a simple query and get the records.
select e1.empname, e2. empname from emp1 e1, emp2 e2 where
e1.empname = e2.empname and e1.empid = e2.empid -
How to find unmatched records in huge tables
Hi,
I want to find out the faster approach, to find records in two tables which do not match.
To make it clear, lets say we have two tables.
table_1(col1 number, col2 varchar2(20), ....other columns)
and
table_2(col3 number, col4 varchar2(20), ....other columns)
col1, col2 from table_1 corresponds to col3, col4 of table_2.
If a record in table_1 does not exists in table_2 or if one of the column has different value, I want to find all such records.
Being Oracle developer, I can easily find that using "outer join" or using "exists".
But want to find out the fastest way, as those table has millions of records.
Maybe using segment or something like that...
Any suggestions?If "the" fastes way would exist oracle would not implement the others.
You will have to test it. The easiest way is to use set autotrace on in sqlplus and compere the consistent gets of both statements (by the way: there is also the MINUS operator with also leads to an outer join but is easier to read).
Dim -
I have two tables - table1 and table2 - that have the exact same schema. There are three fields that can be used to compare the data of the two tables, field1, field2, and field3. When there are matching rows in the two tables (table1.field1/2/3 = table2.field1/2/3)
I want to replace table1.field4 with table2.field4 and replace table1.field5 with table2.field5.
I have worked with the query but have come up with goobly goop. I would appreciate any help. Thanks.If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
How to find structural differences between two tables?
I want to find the difference in structure between objects in two 11g databases:
Here I want to identify:
tables/ Views with same columns, same datatype, precision and constraints
Identify if the same indexes and triggers are present.
I do not want to compare the data.
can someone give suggestions on this please?my first resource for SQL Developer questions is (That) Jeff Smith: http://www.thatjeffsmith.com/archive/2012/09/sql-developer-database-diff-compare-objects-from-multiple-schemas/.
-
How to find common fields between two tables
Hi friends,
Is there any way to find out common fields between tables and linking the tables based on common fields.
Thanks and Regards,
Chitty.Hi Chitty,
Try using joins it will give the fields which are only common to both the fields.
Here s an example,
SELECT mara~matnr
marc~werks
INTO TABLE t_material
FROM mara AS mara INNER JOIN marc AS marc
ON maramatnr = marcmatnr
WHERE mara~mtart = p_mtart.
Much Regards,
Amuktha. -
Finding missing components between two tables
If I had a table named package_part which has several columns:
Site
Parent
Sequence
Child
Qty_per_assembly
Contents eg:
WH1, 123, 1, A, 1
WH1, 123, 2, B, 2
WH1, 123, 3, C, 1
WH2, 123, 1, A, 1
WH2, 123, 2, C, 1
WH2, 123, 3, E, 3
I want to report packages which have missing components between either site.
WH1, 123, 2, B, 2 is missing from site WH2
WH2, 123, 3, E, 3 is missing from site WH1
I just cannot figure it out!
ThanksDepending on your version you could use analytic functions:
WITH package_part AS (SELECT 'WH1' site, 123 parent, 1 SEQUENCE, 'A' CHILD, 1 qty_per_assembly
FROM dual
UNION
SELECT 'WH1', 123, 2, 'B', 2
FROM dual
UNION
SELECT 'WH1', 123, 3, 'C', 1
FROM dual
UNION
SELECT 'WH2', 123, 1, 'A', 1
FROM dual
UNION
SELECT 'WH2', 123, 2, 'C', 1
FROM dual
UNION
SELECT 'WH2', 123, 3, 'E', 3
FROM dual
SELECT site, parent, SEQUENCE, CHILD, qty_per_assembly
FROM (SELECT pp.*, COUNT(*) OVER (PARTITION BY parent, CHILD, qty_per_assembly) no_entries
FROM package_part pp
WHERE no_entries < 2
;There's also a nice article in Oracle Magazine on this topic.
C. -
Relationship between two tables
Hi,
Can some one tell me how can i find the relationship between two tables in CRM. is there any transaction for the same. Is it possible to see the data model.
Thanks
Akila.RHi Nishant ,
Could you please explain brief about the Data relationship ......??
I can see the Foreign Key & Check Table relation in se11 .
Since I am in the Analysing phase ,
what are all the details can i get from Foreign Key & Check table kind relations ...??
Thanks
Rgds
Ganesh -
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. -
I need to implement Drag N Drop between two tables which saves both records
I need to implement Drag N Drop between two tables which saves both records in a third page, by using drag n drop.
check this video http://baigsorcl.blogspot.com/2011/01/drag-and-drop-collection-in-oracle-adf.html
-
Filemaker-how to match and flag records in two tables
Hello,
Tiger.8
Filemaker Pro 8.5 Advanced
I have two related tables in an FMP file.
Table A has ~300 records, B ~2,000.
Each record in A is unique for sure; I believe each one in B is unique.
The goal is to determine whether any of the records in B match one in A based upon student ID.
These IDs are like social security numbers; i.e., they are preassigned, unique 9-character values rather than ones that I'm assigning within FMP.
Like SSNs, these IDs are unique. So within Table A, each ID is unique. Likewise, within B the IDs are unique.
However, some IDs in A might also be in B. I need to find out programmatically which ones, if any, are in both tables.
If a match exists, I need to flag a field in each table.
I found and modified an AppleScript that someone else wrote.
The original is as follows.
tell application "FileMaker Pro"
activate
show every record of database "Original Database"
show every record of database "Old Database"
set field "Match" of document "Original Database" to ""
set orgList to field "Full Name" of document "Original Database"
set oldList to field "Full Name" of document "Old Database"
set matchList to field "Match" of document "Original Database"
repeat with i from 1 to (count of orgList)
if oldList contains item i of orgList then
set item i of matchList to "Match"
end if
end repeat
set field "Match" of document "Original Database" to matchList
show (every record of database "Original Database" whose cell "Match" = "Match")
sort layout 2 of document "Original Database" by field "Last Name"
show layout 2 of document "Old Database"
end tell
My revision is as follows.
tell application "FileMaker Pro Advanced"
activate
show every record of table "A" of document "test"
show every record of table "B" of document "test"
set field "flag" of table "A" of document "test" to ""
set field "flag" of table "B" of document "test" to ""
set AList to field "ID" of table "A" of document "test"
set BList to field "ID" of table "B" of document "test"
set flagList to field "flag" of table "A" of document "test"
repeat with i from 1 to (count of AList)
if BList contains item i of AList then
set item i of flagList to "flag"
end if
end repeat
set field "flag" of table "A" of document "test" to flagList
set field "flag" of table "B" of document "test" to flagList
show (every record of database "test" whose cell "flag" = "flag")
sort layout 1 of document "test" by field "ID"
show layout 1 of document "test"
end tell
I sort of understand what each of the above commands does, but would appreciate answers to the following questions.
1. How come a test record that I created in A and B that has bogus ID 1234 does not get flagged by the above revised script, but other records with valid matching IDs in both A and B do get flagged?
2. How come all records in A that got flagged by the revised script do have counterparts in B, but only some of the ones in B that have a match in A got flagged?
3. How do the commands "set Alist" and "set Blist" function?
4. How do I fix the revised script so that it properly, correctly matches IDs between A and B, then properly, correctly flags the records in A and B that have matching IDs?
Many thanks in advance and happy weekend!
G4/1.25 MDD Mac OS X (10.4.8)>
as there any way find out using comparison same records in two tables..........
>
>
if i write a query then i can easily understand the same data is existed in two tables
>
So, what is your problem now?
You can join both the tables using a simple query and get the records.
select e1.empname, e2. empname from emp1 e1, emp2 e2 where
e1.empname = e2.empname and e1.empid = e2.empid -
How to fetch records between two seq uence numbers?
We have thousands of records with seq uence numbers in the oracle database, we need to retrieve a number of records between two seq uence numbers, i.e. to retrieve records between 100 and 200 seq uence numbers. Could some one help me to find a query to fetch records.
I'll be waiting for your response..
Edited by: sumant on Jul 27, 2010 12:42 PMIs this is what you are looking for?
SQL> create table tab1 (id number);
Table created.
SQL> insert into tab1 values (1);
1 row created.
SQL> insert into tab1 values (2);
1 row created.
SQL> insert into tab1 values (3);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from tab1;
ID
1
2
3
SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
2 from tab1;
RANDOM_NUMBER
43
SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
2 from tab1;
RANDOM_NUMBER
39
SQL> select round(dbms_random.value(max(id)+1,max(id)+50)) random_number
2 from tab1;
RANDOM_NUMBER
13 This will generate a random number that will be greater then the maximum value in the table and lower then the maxvalue + 50. Having the range starting from maxvalue in the table you will never get a number generated which already exists in the table.
As you see in the above number genrated they are all between 4 and 53.
If you want to increase the range from where the number are generated just increase the value 50 that I used in the query. -
Find the difference between two columns in an ssrs matrix ? MSCRM
Hi All,
I am working in reporting part of our project (On-line MSCRM 2013) & in reporting services.
I am trying to create report using fetch xml based. Below is the snap what we required the result.
Kindly help me, how to get the difference in both column. (Its a matrix table where year is grouped).
We need difference between both year Like (Plan Revenue of 2013 & Plan Revenue of 2014 difference in Plan Revenue Diff section) and same for Actual
Revenue.
https://social.microsoft.com/Forums/en-US/054d5ca4-0d38-4dc6-84a8-88866cc228fe/find-the-difference-between-two-columns-in-an-ssrs-matrix-mscrm?forum=crmdevelopment
Thanks,
Mohammad ShariqueHi Bro,
I used parametrized option for year and done the report,Currently we are getting values in Difference column now i want to show
that value in percentage. How can we show the percentage based on that value. Means i want to show the Difference in Percentage.
Kindly help me i tried but getting some issue. Below i am mentioning the code and snap with result.
Below expression using to showing Plan Revenue in Percentage for year.
=
Sum(IIF(Fields!new_year.Value =Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
- Sum(IIF(Fields!new_year.Value =Parameters!EndYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
/IIF(Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))>0,
(Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0))))
,1)
)*100))
Result issue is as below in snap with highlighted in red colour.
Kindly help me on this issue also :)
Maybe you are looking for
-
I downloaded and installed update 3.6.15 when I try to launch firefox I get a XULRunner error Platform Version '1.9.2.15 is not compatible with minVersion >= '1.9.2.13' maxVersion <='1.9.2.13' How can I fix this?
-
This might be a real stupid question but I cannot figure this out. On my iphone 4 when I take photos using the camera ON GOOGLE, where do those photos go-. I cannot find them at all-.
-
Weird Text display in Mail & Safari
Whenever I use Safari or My OS X Mail, I get certain text that will show up in weird characters. This does not happen when I use Explorer as my internet browser or my email from any other application. Does anyone know why this is or how to change it?
-
How do you fix a non-loading movie on your iPod?
I have an iPod touch 4. I just downloaded a movie. I had lots of space to do so. Now I'm trying to watch the movie and a button keeps comin up and it says "unable to load movie." What is wrong?! I was wondering how you get it to load. It's a two hour
-
HT6114 MAC Air slow to boot after 10.9.2 update.
I have a 2011 MAC Air. After the 10.9.2 upgrade my laptop takes about 20 minutes to boot from power off. Once started it works fine, it is just extremely slow to boot. Prior to the update I could boot in about 10 seconds. Any thoughts how to resolve