473,397 Members | 1,960 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,397 software developers and data experts.

DB2 Syntax for Outer join

Sri
Hi,

I am new to DB2 and I am using DB2 UDB 8.1 for Windows. I have a query
which works fine in ORACLE and I am trying to find out equivalent
query in DB2.

SELECT
sessi.ses sessions,
sp1.speaker speaker1,
sp2.speaker speaker2,
sp3.speaker speaker3
FROM
(SELECT ses FROM db2admin.sp GROUP BY ses) sessi,
(SELECT ses, speaker FROM sp a WHERE 1 = (SELECT COUNT
(DISTINCT (speaker)) FROM db2admin.sp b WHERE ses = a.ses AND
b.speaker >= a.speaker)) sp1,
(SELECT ses, speaker FROM sp a WHERE 2 = (SELECT COUNT
(DISTINCT (speaker)) FROM db2admin.sp b WHERE ses = a.ses AND
b.speaker >= a.speaker)) sp2,
(SELECT ses, speaker FROM sp a WHERE 3 = (SELECT COUNT
(DISTINCT (speaker)) FROM db2admin.sp b WHERE ses = a.ses AND
b.speaker >= a.speaker)) sp3
WHERE
sessi.ses = sp1.ses(+) AND
sessi.ses = sp2.ses(+) AND
sessi.ses = sp3.ses(+)
ORDER BY
sessi.ses

Here is the output of the above Query
----------------------------------------------
SESSSIONS SPEAKER1 SPEAKER2 SPEAKER3
S1 Surya Srihari Ravi
S2 Savi2 Ravi
S3 Savi3

The actual content of the table is
---------------------------------------------
Sessions Speaker
s1 Surya
s1 Srihari
s1 Ravi
s2 Savi1
s2 Ravi
s3 Savi2
Nov 12 '05 #1
2 19238
Mapping from (+) syntax to SQL Standard outer join is described in the
Oracle docs.

Meanwhile try this.. the original SQL hurts my head. :-)
SELECT session,
MAX(case when spno = 1 then speaker else '' end) as speaker1
MAX(case when spno = 2 then speaker else '' end) as speaker2
MAX(case when spno = 3 then speaker else '' end) as speaker3
FROM
(SELECT session,
row_number()
over (partition by session
order by speaker) as spno,
speaker
FROM sp) AS sp
GROUP BY session
ORDER BY session

Cheers
Serge

PS: In case you are porting: The same syntax should work in Oracle as well
Nov 12 '05 #2

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

Similar topics

3
by: Phil Powell | last post by:
I'm not kidding, the only reason yesterday you didn't hear from me was because I wasn't coding, but today I am doing something quick, and yes, as always it failed.. right at the SQL statement: ...
23
by: middletree | last post by:
I've seen posts here and elsewhere which read something along the lines of "PULLNG MY HAIR OUT!!!!!" or "HELLLLPPP!". Well, I know that kind of subject line isn't descriptive, but I sure can...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
2
by: Martin | last post by:
I am now working on SQL Server 2000 having had previous experience on a different database. Both of the OUTER JOIN syntaxes is different from what I am used to and I am finding it slightly...
2
by: Anthony | last post by:
I have an inventory database that Im trying to create a report out of the IP address are a lookup on a seperat table but I keep getting the above error can I change the table row to something to...
3
by: mheydman | last post by:
I apologize if this has been asked before- I searched google but could not find a concrete answer. I recently inherited a database whose t-sql code is written in a format that I find difficult...
1
by: csomberg | last post by:
SQL Server 2000 When joining tables, some use: AliasTableName.ColumnName = AliasTableName.Column while others use LEFT/RIGHT etc JOIN ....... Is one better than the other in cases where the...
3
by: Doug | last post by:
Hi, I'm more familiar with MSSQL than Access syntax and have run into a problem with correctly putting ( )'s around the joins in a 3 table query. I want to INNER JOIN lenders and accounts and...
3
by: jared.pohl | last post by:
Hi guys.. When I try and run the following code it says that there is a missing operator.. SELECT curr.portfolio_code, curr.date, (curr.gross_index-mo1.gross_index)/mo1.gross_index AS...
5
by: allik7 | last post by:
Declare @String as nVarChar(1000) Declare @Ind as Char(1),@Com as Char(1),@BAC3 as Char(1) Declare @BAC1 as Char(1),@BAC2 as Char(1),@BAC4 as Char(1) Declare @current as varChar(7),@saving as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.