473,915 Members | 7,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LEFT OUTER JOIN's possible in DB2?

i know nothing about DB2, but i'm sure this must be possible.

i'm trying to get a client to create a view (which it turns out is called a
"Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know
how to do that, or even if he can, and i don't have to time to learn DB2
from scratch right now.

The following SQL Query is a trimmed sample of the full View (i.e. Logical)
definition - and i would create it on an SQL based databse engine:

SELECT
CustomerMaster. SYIDCM, --[KeyField]
CustomerMaster. FN@CM, --First name
CustomerMaster. MI@@CM, --Middle Initial
CustomerMaster. LN@@CM, --Lastname

CustomerBusines sAddress.SYIDCI C, --[Key Join Field]
CustomerBusines sAddress.MAILCA , --Mail Code
CustomerBusines sAddress.AD1@CA , --Business Address 1
CustomerBusines sAddress.AD2@CA , --Business Address 2
CustomerBusines sAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusines sAdress
ON CustomerMaster. SYIDCM = CustomerBusines sAddress.SYIDCA
AND CustomerBusines sAddress.MAILCA = 'B'

Part of the full logical definition he gave me is:

JDFTVAL
R CMS2 JFILE(CSPCM CSPCX CSPCA +
CSPCP CSPCIC)
J JOIN(CSPCM CSPCX)
JFLD(SYIDCM SYIDCX)
J JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
J JOIN(CSPCM CSPCP)
JFLD(SYIDCM SYIDCP)
J JOIN(CSPCM CSPCIC)
JFLD(SYIDCM SYIDCIC)
SYIDCM JREF(1)
FNM@CM
MI@@CM
LNM@CM
SEX@CM
...

Now be being a guy who grew up with SQL, this syntax is...horrible - but i
can sorta see what's happening.

Isn't there a syntax to do outer joins? So that instead of

J JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
JFLD(MAILCA 'B')

it's

LJ JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
JFLD(MAILCA 'B')

Where LJ is left join?

or maybe

J JOIN(CSPCM CSPCA)
LEFTJFLD(SYIDCM SYIDCA)
LEFTJFLD(MAILCA 'B')

Like i said, i have NO idea what this syntax is; i'm just guessing.

Is a LEFT JOIN join possible in DB2?
Nov 12 '05 #1
3 23106

"Ian Boyd" <ia***********@ avatopia.com> wrote in message
news:cg******** @enews2.newsguy .com...
i know nothing about DB2, but i'm sure this must be possible.

i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know
how to do that, or even if he can, and i don't have to time to learn DB2
from scratch right now.

The following SQL Query is a trimmed sample of the full View (i.e. Logical) definition - and i would create it on an SQL based databse engine:

SELECT
CustomerMaster. SYIDCM, --[KeyField]
CustomerMaster. FN@CM, --First name
CustomerMaster. MI@@CM, --Middle Initial
CustomerMaster. LN@@CM, --Lastname

CustomerBusines sAddress.SYIDCI C, --[Key Join Field]
CustomerBusines sAddress.MAILCA , --Mail Code
CustomerBusines sAddress.AD1@CA , --Business Address 1
CustomerBusines sAddress.AD2@CA , --Business Address 2
CustomerBusines sAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusines sAdress
ON CustomerMaster. SYIDCM = CustomerBusines sAddress.SYIDCA
AND CustomerBusines sAddress.MAILCA = 'B'

Part of the full logical definition he gave me is:

JDFTVAL
R CMS2 JFILE(CSPCM CSPCX CSPCA +
CSPCP CSPCIC)
J JOIN(CSPCM CSPCX)
JFLD(SYIDCM SYIDCX)
J JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
J JOIN(CSPCM CSPCP)
JFLD(SYIDCM SYIDCP)
J JOIN(CSPCM CSPCIC)
JFLD(SYIDCM SYIDCIC)
SYIDCM JREF(1)
FNM@CM
MI@@CM
LNM@CM
SEX@CM
...

Now be being a guy who grew up with SQL, this syntax is...horrible - but i
can sorta see what's happening.

Isn't there a syntax to do outer joins? So that instead of

J JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
JFLD(MAILCA 'B')

it's

LJ JOIN(CSPCM CSPCA)
JFLD(SYIDCM SYIDCA)
JFLD(MAILCA 'B')

Where LJ is left join?

or maybe

J JOIN(CSPCM CSPCA)
LEFTJFLD(SYIDCM SYIDCA)
LEFTJFLD(MAILCA 'B')

Like i said, i have NO idea what this syntax is; i'm just guessing.

Is a LEFT JOIN join possible in DB2?
You haven't said which version of DB2 you are using or what platform you are
on. Your examples don't look like SQL from any of the platforms I have used
except possibly AS/400 which I used for a few days once several years (and
version of DB2) ago. The answer to virtually *any* DB2 question depends on
your DB2 version and your OS so I can only make some general remarks.

Left joins are possible on the last few versions of DB2 on
Windows/Unix/Linux/OS/2 and also on OS/390. I don't recall if they are
available on AS/400. Although I used DB2 for VM for a while in its first
release, that was in the mid 1980s and I haven't seen it since; I don't know
if left joins are available in DB2 for VM/VSE today.

You can find the manuals for DB2 on all platforms (except AS/400) at
http://www-306.ibm.com/software/data...nfocenters.jsp. You'll
need to track down the AS/400 manuals yourself at the IBM website. Try a
search on "AS/400 DB2" at http://www.ibm.com.

The manual that contains the rules of SQL syntax for DB2 is called SQL
Reference on Windows/Unix/Linux and OS/390. I'm not sure if the same applies
to VM/VSE and AS/400.

For what it's worth, I've never called a "view" a "logical" in 20 years of
using DB2. I've occasionally described a view as a "logical table" but
normally I just call it a "view".

Also, the query at the beginning of your question -

SELECT CustomerMaster. SYIDCM, --[KeyField]
CustomerMaster. FN@CM, --First name
CustomerMaster. MI@@CM, --Middle Initial
CustomerMaster. LN@@CM, --Lastname

CustomerBusines sAddress.SYIDCI C, --[Key Join Field]
CustomerBusines sAddress.MAILCA , --Mail Code
CustomerBusines sAddress.AD1@CA , --Business Address 1
CustomerBusines sAddress.AD2@CA , --Business Address 2
CustomerBusines sAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusines sAdress
ON CustomerMaster. SYIDCM = CustomerBusines sAddress.SYIDCA
AND CustomerBusines sAddress.MAILCA = 'B'


- looks perfectly fine to me. The FROM clause ought to work on any platform
that supports Left Joins just the way it is written here.

The "logical definition" you have given doesn't look like anything I've ever
seen before. However, if this is AS/400, it may be perfectly valid. I've
always found AS/400 the most "different" of the DB2 platforms.

You'll want to look at the CREATE VIEW statement in your platform's SQL
Reference to see the exact syntax for creating a view.

Lastly, it's been my experience that users tend to mess up joins if left to
do them on their own. (Not *all* users write bad joins but quite a few seem
to fall into this category). They often forget the joining condition
entirely or sometimes choose the wrong columns to join. Unless you plan to
approve their queries somehow after the users have written them, you may
find that it is better for you to create views for them that include
properly-written joins, then let the users built their queries against the
views rather than against the base tables. Just a thought....

Rhino
Nov 12 '05 #2
> You haven't said which version of DB2 you are using or what platform you
are
on.
That would be because i don't know.

i don't know an AS400 from a DB2.
Your examples don't look like SQL from any of the platforms I have used
except possibly AS/400 which I used for a few days once several years (and
version of DB2) ago.
It's an AS/400. They all call it the AS/400.
You can find the manuals for DB2 on all platforms (except AS/400)
*grin*
You'll need to track down the AS/400 manuals yourself at the IBM website.
Try a search on "AS/400 DB2" at http://www.ibm.com. Also, the query at the beginning of your question -
- looks perfectly fine to me. The FROM clause ought to work on any platform that supports Left Joins just the way it is written here.
Yeah, that was my version of how i would accomplish what i need done in the
as/400.
Unfortunatly, they can't figure out a left join syntax.

Hopefully someone here knows it.
You'll want to look at the CREATE VIEW statement in your platform's SQL
Reference to see the exact syntax for creating a view.
Their IBM thingy doesn't use SQL. It uses whatever that funky syntax is.

The "logical definition" you have given doesn't look like anything I've ever seen before. However, if this is AS/400, it may be perfectly valid. I've
always found AS/400 the most "different" of the DB2 platforms.


And then it hits you. You are so tired of IBM.
Nov 12 '05 #3
Found it.

There's a keyword

JDEFVAL

that makes all joins FULL OUTER joins

It's not at all what i wanted, but it's damn near closer enough.
"And that's when it hits you. You are so tired of IBM."
"Amanda" <ne*********@zu nblvlda1.dyndns .org> wrote in message
news:cg******** @enews3.newsguy .com...
You haven't said which version of DB2 you are using or what platform you are
on.


That would be because i don't know.

i don't know an AS400 from a DB2.
Your examples don't look like SQL from any of the platforms I have used
except possibly AS/400 which I used for a few days once several years (and version of DB2) ago.


It's an AS/400. They all call it the AS/400.
You can find the manuals for DB2 on all platforms (except AS/400)


*grin*
You'll need to track down the AS/400 manuals yourself at the IBM website. Try a search on "AS/400 DB2" at http://www.ibm.com.

Also, the query at the beginning of your question -
- looks perfectly fine to me. The FROM clause ought to work on any

platform
that supports Left Joins just the way it is written here.


Yeah, that was my version of how i would accomplish what i need done in

the as/400.
Unfortunatly, they can't figure out a left join syntax.

Hopefully someone here knows it.
You'll want to look at the CREATE VIEW statement in your platform's SQL
Reference to see the exact syntax for creating a view.


Their IBM thingy doesn't use SQL. It uses whatever that funky syntax is.

The "logical definition" you have given doesn't look like anything I've

ever
seen before. However, if this is AS/400, it may be perfectly valid. I've
always found AS/400 the most "different" of the DB2 platforms.


And then it hits you. You are so tired of IBM.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7865
by: KT | last post by:
This might not be possible, but on the chance that it can - is there a way to do the following: Given a arbitray one dimesional value list: ('AALGX','12345','XXXXX','AAINX','AMMXX') Is there a way that I could do a select statement, or similiar, in the value list, to get the following result field_name
5
8225
by: Todd | last post by:
Data related to the query I'm working on is structured such that TableA and TableB are 1-many(optional). If an item on TableA has children on TableB, I need to use the Max(tstamp) from Table B in a condition, otherwise I need to use a tstamp from TableA (note:there are additional tables and conditions for this query, but this problem is based around these 2). I attempted having TableB (as B) "left outer joined" to TableA, and a condition...
3
7567
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total, qryTxToQ3.Q3Total, qryTxToQ4.Q4Total FROM qryTxToQ4 OUTER JOIN (qryTxToQ3 OUTER JOIN (qryTxToQ1 OUTER JOIN qryTxToQ2 ON qryTxToQ1.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ3.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ4.TxAcct_ID = qryTxToQ3.TxAcct_ID;
14
5748
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some ItemIDs in LogEvent do not correspond to ItemIDs in Item, and periodically we need to purge the non-matching ItemIDs from LogEvent. The query is: delete from LogEvent where EventType != 'i' and ItemID in
8
1581
by: alex | last post by:
Thanks in advance for any help. I'm trying to attempt the following with one table/query. I have a table called TABLE_1 It has the following fields: SSN TITLE LOCATION 322 EX DALLAS 568 REP FT_WORTH 536 EX DALLAS
0
2460
by: hdogg | last post by:
I am using oracle with php. I am trying to accomplish a left outer join. Here are the 3 queries. Query 1, contains all the data on the left the will show up with data on the right. Query 1 = ((SELECT JOB_CODE AS JOBCODE , PERIOD FROM GSI.PCTCOMP_ACC_VW WHERE ( PCT_DATE = TO_DATE('20070228000000','YYYYMMDDHH24MISS') ) AND ( PCT_COMP_CODE = '02' ))) Query 2:
9
9232
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to filter my left table in the WHERE clause and cannot filter it in the FROM clause. This seems like it would cause a lot of overhead especially when my left table is ten thousand rows. Am I wrong in thinking that the two tables get joined with the...
0
1334
by: gr8white | last post by:
I'm running a query involving an outer join where one of the conditions is that the numeric value of a varchar field is between the numeric values of 2 varchar fields in another table (this has to do with an address range where in some cases the addresses include an alpha character). The query runs fine in the original database but for some reason it returns an "invalid number" error in another db against the exact same data, even though I am...
3
2102
by: jwwarrenva | last post by:
All, I am far from expert with SQL and have been unable to solve the following problem (stated in generic terms): I have three tables: 1. Employees - contains EmployeeName 2. Years - contains Year 3. Earnings - contains Year, EmployeeName, and Earnings
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5944
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.