473,289 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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

CustomerBusinessAddress.SYIDCIC, --[Key Join Field]
CustomerBusinessAddress.MAILCA, --Mail Code
CustomerBusinessAddress.AD1@CA, --Business Address 1
CustomerBusinessAddress.AD2@CA, --Business Address 2
CustomerBusinessAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusinessAdress
ON CustomerMaster.SYIDCM = CustomerBusinessAddress.SYIDCA
AND CustomerBusinessAddress.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 23059

"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

CustomerBusinessAddress.SYIDCIC, --[Key Join Field]
CustomerBusinessAddress.MAILCA, --Mail Code
CustomerBusinessAddress.AD1@CA, --Business Address 1
CustomerBusinessAddress.AD2@CA, --Business Address 2
CustomerBusinessAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusinessAdress
ON CustomerMaster.SYIDCM = CustomerBusinessAddress.SYIDCA
AND CustomerBusinessAddress.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

CustomerBusinessAddress.SYIDCIC, --[Key Join Field]
CustomerBusinessAddress.MAILCA, --Mail Code
CustomerBusinessAddress.AD1@CA, --Business Address 1
CustomerBusinessAddress.AD2@CA, --Business Address 2
CustomerBusinessAddress.CTY@CA --Business City

FROM CSPCM CustomerMaster
LEFT OUTER JOIN CSPCA CustomerBusinessAdress
ON CustomerMaster.SYIDCM = CustomerBusinessAddress.SYIDCA
AND CustomerBusinessAddress.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*********@zunblvlda1.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
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...
5
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...
3
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,...
14
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...
8
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...
0
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 =...
9
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...
0
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...
3
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 -...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.