473,698 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Second join based on the lack of success of the first

I only want to do second join if the first was unsuccessful and was
wondering if something like the following would be valid:

select t1.*, t2.*, t3.*
from t1
left outer join table
(select ta.*, tb.uniquename
from ta
left outer join tb on tb.key=ta.key
where ta.key=t1.key) t2 on 0=0
left outer join table
(select tc.*
from tc
where tc.key=t1.key
and t2.key is null) t3 on 0=0

The real questions are: is the reference to t2.key in t3 valid; and will
it be null if t2 fails to match?

The above query is an extremely simplified form of the real query, which
would be 125-150 lines long in a (semi) readable format.
Feb 8 '06 #1
2 1469
Bob Stearns wrote:
I only want to do second join if the first was unsuccessful and was
wondering if something like the following would be valid:

select t1.*, t2.*, t3.*
from t1
left outer join table
(select ta.*, tb.uniquename
from ta
left outer join tb on tb.key=ta.key
where ta.key=t1.key) t2 on 0=0
left outer join table
(select tc.*
from tc
where tc.key=t1.key
and t2.key is null) t3 on 0=0

The real questions are: is the reference to t2.key in t3 valid; and will
it be null if t2 fails to match?

The above query is an extremely simplified form of the real query, which
would be 125-150 lines long in a (semi) readable format.

select t1.*, t2.*, t3.*
from t1
left outer join table
LATERAL(select ta.*, tb.uniquename
from ta
left outer join tb on tb.key=ta.key
where ta.key=t1.key) t2 on 0=0
left outer join table
LATERAL(select tc.*
from tc
where tc.key=t1.key
and t2.key is null) t3 on 0=0

This is lateral correlation, hence you need teh lateral keyword.
If in your version of DB2 LATERAL gives a syntax error, try TABLE instead.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Feb 8 '06 #2
You can refere to t2.key in t3.
and will it be null if t2 fails to match?

I think so.

My question:
You wrote "The above query is an extremely simplified ..."
But, can you remove second subselect to simplify the statement?

select t1.*, t2.*, t3.*
from t1
left outer join table
(select ta.*, tb.uniquename
from ta
left outer join tb on tb.key=ta.key
where ta.key=t1.key) t2 on 0=0
left outer join
tc t3
ON t3.key=t1.key
and t2.key is null

Feb 9 '06 #3

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

Similar topics

6
3070
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
0
1611
by: Alex Martelli | last post by:
Greetings, fellow Pythonistas! We (Alex Martelli, David Ascher and Anna Martelli Ravenscroft) are in the process of selecting recipes for the Second Edition of the Python Cookbook. Please contribute your recipes (code and discussion), along with comments on and ratings of existing recipes, to the cookbook site, http://aspn.activestate.com/ASPN/Cookbook/Python , and do it *now*! The Python Cookbook is a collaborative collection of your...
31
2427
by: Brian Sabbey | last post by:
Here is a pre-PEP for what I call "suite-based keyword arguments". The mechanism described here is intended to act as a complement to thunks. Please let me know what you think. Suite-Based Keyword Arguments ----------------------------- Passing complicated arguments to functions is currently awkward in Python. For example, the typical way to define a class property winds up polluting the class's namespace with the property's get/set...
0
1394
by: YellowFin | last post by:
Announcing Yellowfin Information collaboration and reporting tool Drag and Drop Report Builder Simple to Deploy and Administer Enterprise Level Web Based Reporting
30
3119
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and wish that my predecessor had followed) but -- alas -- being a relative beginner to Access, I can't see the reasoning behind one of the points and the site does not provide any rationale / explanation for its presence either: 2. Thou shalt never...
1
20542
by: Gene Ariani | last post by:
I have one dataset that contains two DataTables: DataTable1: Customer_ID 1
4
1408
by: randfish | last post by:
We're seeking to hire a local (Seattle-based) PHP/MySQL coder to handle a project, but have been having no success. I was hoping to get your feedback on whether the pricing, timeframe and job demands seemed reasonable and what the reasons might be for the lack of interest shown thus far (I posted on CL - http://seattle.craigslist.org/art/131871889.html - and received virtually no response). Project Description: The project requires a...
4
2038
by: Dabbler | last post by:
I need to convert a CompanyId in one table to Company Name from another table for an ItemTemplate. I thought I would just add another SqlDataSource but not sure how to eval with the CompanyId parameter for the where clause in the select. Any clues would be appreciated.
1
2776
by: Arved Sandstrom | last post by:
This seems to be something so simple that none of the hundred-odd tutorials and forum threads that I have looked at (:-)) apparently thinks it's a problem. In a nutshell, I have two DataGridViews. Each has a BindingSource (and a BindingNavigator). The first view populates successfully based upon a Linq to SQL query in the Form Load (that is, the query is assigned to the DataSource of that view's BindingSource, and the BindingSource is...
0
8609
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
9030
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...
1
8899
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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
7738
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4371
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...
1
3052
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
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.