473,570 Members | 2,940 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 23080

"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
7798
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
8203
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...
3
7535
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 =...
14
5680
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:...
8
1569
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
2449
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...
9
9206
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...
0
1319
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...
3
2087
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
7636
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...
0
7948
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8150
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...
1
7700
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3671
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2131
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
0
971
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...

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.