View previous topic :: View next topic |
Author |
Message |
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Mon Mar 26, 2012 8:03 am Post subject: Pick Missing Empno from table |
|
|
Hi,
I have 2 tables t1 and t2 , here i need to compare the tables and pick those records which do not a empno in T1
table 1
Code: |
tin-nbr empno
1001 1
1002 2
1003 6
|
table 2
Code: |
acct no empno
001 1
002 6
|
Thanks
Raj |
|
Back to top |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Mon Mar 26, 2012 9:43 am Post subject: |
|
|
If I understand you correctly this should work:
Code: |
SELECT T2.EMPNO
FROM TABLE2 T2
LEFT JOIN TABLE1 T1 ON T2.EMPRNO = T1.EMPRNO
WHERE T1.EMPRNO IS NULL
|
_________________ Thanks,
NASCAR9 |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Mon Mar 26, 2012 10:40 am Post subject: |
|
|
ok. by this we will not be getting the desired o/p as "2" , and also none of the fields will have null values.
Thanks,
Raj |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Mar 26, 2012 11:05 am Post subject: |
|
|
rajeev5174,
Please use meaningful titles to your questions. It would have been nice if you had showed the desired output.
Assuming you want the rows from table1 that does not have a matching empno from table2 then you can use the following untested sql
Code: |
SELECT *
FROM TABLE1
WHERE EMPNO NOT IN (SELECT EMPNO
FROM TABLE2)
; |
The output from this would be
Kolusu |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Mon Mar 26, 2012 12:16 pm Post subject: |
|
|
ok Kolusu, the issue here is the datatype of one is binary and the other is character , i used the cast function, it is saying the "OPERANDS OF AN ARITHMETIC OR COMPARISON OPERATION ARE NOT COMPARABLE "
Thanks,
Raj |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Mar 26, 2012 12:22 pm Post subject: |
|
|
rajeev5174 wrote: | ok Kolusu, the issue here is the datatype of one is binary and the other is character , i used the cast function, it is saying the "OPERANDS OF AN ARITHMETIC OR COMPARISON OPERATION ARE NOT COMPARABLE "
Thanks,
Raj |
Am I supposed to read your mind? which column is binary ? and which column is character? Post detailed information on what you're trying to accomplish. Do not make people guess what you mean. This will give you a much better chance of getting a good answer to your question.
Kolusu |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Mon Mar 26, 2012 12:40 pm Post subject: |
|
|
ok. empno in table (t1) is binary and that empno in table t2 is character of length 30.
Regards
Ron |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Mar 26, 2012 12:55 pm Post subject: |
|
|
rajeev5174 wrote: | ok. empno in table (t1) is binary and that empno in table t2 is character of length 30.
Regards
Ron |
*Sigh* A binary column ind DB2 ( Smallint or integer) will occupy 2 or 4 bytes. How do you plan to compare that value with a column of character data of 30 bytes?
Are the numbers in the char column right justified or left justified? You need to do a better job of showing how the data looks like in the character column.
Kolusu |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Tue Mar 27, 2012 7:50 am Post subject: |
|
|
ok kolusu.
The Empno in T1 is S9(09) COMP & in the 2'nd table the data is x(30).
The data in t2 is shown as '000000008'
Regards
Raj |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Mar 27, 2012 7:55 am Post subject: |
|
|
still don't know if:
1. left or right justified
2. is the values decimal data, or is a binary field moved to a char column.
if it would not bother you to much, Raj, to provide answers to above questions. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Mar 27, 2012 10:30 am Post subject: |
|
|
rajeev5174,
You are wasting your time as well as our time. I am assuming the character data is left justified in the character column and it is just 10 bytes long.
Code: |
SELECT *
FROM TABLE1
WHERE EMPNO NOT IN (SELECT INT(SUBSTR(EMPNO,1,10))
FROM TABLE2)
;
|
Kolusu |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Thu Mar 29, 2012 7:36 am Post subject: |
|
|
Thanks kolsu, the issue is query is hanging as the tables are having more 7 billons reords.. so we need to unload to flat file and do a file matching..that is my thought
Regards
Rajeev V |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Mar 29, 2012 10:14 am Post subject: |
|
|
rajeev5174 wrote: | Thanks kolsu, the issue is query is hanging as the tables are having more 7 billons reords.. so we need to unload to flat file and do a file matching..that is my thought
Regards
Rajeev V |
rajeev5174,
Please spell my name properly. What do you plan to do with this query? You want to look at 7 billion records manually ? _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
rajeev5174 Beginner
Joined: 05 Jun 2007 Posts: 25 Topics: 10
|
Posted: Thu Mar 29, 2012 12:18 pm Post subject: |
|
|
Apologies for spelling your name incorrectly.. The issue i am facing is that the query is hanging when i ran in the system, working fine the data size is of a smaller size , so i believe we may need to unload to a flat file and using a easytrive or cobol match logic we can find the unmatched empno's
Regards
Raj |
|
Back to top |
|
|
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Thu Mar 29, 2012 6:15 pm Post subject: |
|
|
Anything done with 7 billion entries is going to take time. . .
If you unload compare data, and all that is wanted is the list of "missing key values", only unload the keys and make sure that both are in the same data format (which will allow direct cmpares with no data conversion in the compare operation. This will also give the smallest sets of "compare data" which will both run faster and use less transient dasd space. _________________ All the best,
di |
|
Back to top |
|
|
|
|