IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Distinct vendor number from 2 tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
madmartinsonxx

New User


Joined: 10 Dec 2010
Posts: 96
Location: Massachusetts

PostPosted: Fri Feb 18, 2011 9:20 pm
Reply with quote

Code:

SELECT DISTINCT B.LEGACY_VEND_NR           
  FROM DAAVEND.VENDOR A,                   
       DAAVEND.PAYEE  B                     
  WHERE B.LEGACY_VEND_NR = A.LEGACY_VEND_NR;


I am trying to get just one vendor number from 2 tables. If it exists in just one table I need that in the result set. If the vendor number appears in both tables I just need one in the result set.
I don't think the code above will do that. I think he will just pick the ones in the PAYEE table.
We run Version 9 Release 1.
There is another application I will need this process for and once I get this licked I can wrassle the next one down no problem. Thanks !
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Fri Feb 18, 2011 9:37 pm
Reply with quote

Your query as written will return a value only if both tables contain the same vendor number.

An Outer Join should do the trick. Or a Union.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Fri Feb 18, 2011 9:50 pm
Reply with quote

Hi Martin,
It sounds like you are just looking for that Vendor number and it doesn't matter in which table it is found. In that case, you can something like this,

Code:
SELECT LEGACY_VEND_NR           
  FROM DAAVEND.VENDOR
Union
SELECT LEGACY_VEND_NR
  FROM DAAVEND.PAYEE


Thanks,
Sushanth
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Feb 18, 2011 9:54 pm
Reply with quote

basic SQL : UNION


"Mainframe Skills: DB2, IDMS, SAP, Oracle " ? I don't think so
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Increase the number of columns in the... IBM Tools 3
No new posts Cobol program with sequence number ra... COBOL Programming 5
Search our Forums:

Back to Top