MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pick Missing Empno from table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Mon Mar 26, 2012 8:03 am    Post subject: Pick Missing Empno from table Reply with quote

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
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Mon Mar 26, 2012 9:43 am    Post subject: Reply with quote

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
View user's profile Send private message
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Mon Mar 26, 2012 10:40 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 26, 2012 11:05 am    Post subject: Reply with quote

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
Code:

       1002            2     


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Mon Mar 26, 2012 12:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 26, 2012 12:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Mon Mar 26, 2012 12:40 pm    Post subject: Reply with quote

ok. empno in table (t1) is binary and that empno in table t2 is character of length 30.

Regards
Ron
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 26, 2012 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Tue Mar 27, 2012 7:50 am    Post subject: Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Mar 27, 2012 7:55 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Mar 27, 2012 10:30 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Thu Mar 29, 2012 7:36 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Mar 29, 2012 10:14 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
rajeev5174
Beginner


Joined: 05 Jun 2007
Posts: 25
Topics: 10

PostPosted: Thu Mar 29, 2012 12:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Mar 29, 2012 6:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group