G'day Atrix, At 12:48 02/11/02 -0800, you wrote:
i have a main table 'TableA' with 2 id fields...IDB and IDC. I have 2 other tables..TableB and TableC. What i need to do is left join TableA with both those tables while also limiting IDA to a specific value. Simplified i need to look up some rows in tableA and then grab the data from TableB using those IDB's in TableA and do the same with TableC and the IDC's in TableB. I cant seem to get it to work in a single statement...Yes and no.
this is the closest i got but it isnt workin ):
select * from TableA left join TableB on TableA.IDB=TableB.IDB left join TableC on TableA.IDC=TableB.IDC where TableA.IDA=435
is something like this doable?
It is but I have not found a way to do it in a single statement.
I would do it this way:
CREATE TEMPORARY VIEW `VW_1` +
(IDA,IDB,OtherCols) +
AS SELECT +
t1.IDA,t2.IDB,OtherCols +
FROM TableA t1 +
LEFT OUTER JOIN TableB t2 +
ON t2.IDB = t1.IDB +
WHERE t1.IDA=435
CREATE TEMPORARY VIEW `VW_2` +
(IDA,IDB,OtherCols) +
AS SELECT +
t1.IDA,t1.IDB,OtherCols,t2.IDC,OtherCols +
FROM VW_1 t1 +
LEFT OUTER JOIN TableC t2 +
ON t2.IDB = t1.IDB
By explicitly naming the column names in the view you
get the advantage of being able to select from the
columns without the ID columns being present twice.
If the views are to be used with multiple ID parameters
you could leave off the WHERE t1.IDA=435 from the first view
although you may suffer a serious speed issue on larger
data sets.
Warmest regards,
Tom Grimshaw
coy: Just For You Software
tel: 612 9552 3311
fax: 612 9566 2164
mobile: 0414 675 903
post: PO Box 470 Glebe NSW 2037 Australia
street: 3/66 Wentworth Park Rd Glebe NSW 2037
email: [EMAIL PROTECTED]
web: www.just4usoftware.com.au
"... the control of impulse -- is the first principle of civilization."-- Will Durant,
Pulitzer Prize winning philosopher, writer and historian
the most needed product in the world can be found at
www.thewaytohappiness.org
This email and any files transmitted with it are confidential to the intended recipient and may be privileged. If you have received this email inadvertently or you are not the intended recipient, you may not disseminate, distribute, copy or in any way rely on it. Further, you should notify the sender immediately and delete the email from your computer. Whilst we have taken precautions to alert us to the presence of computer viruses, we cannot guarantee that this email and any files transmitted with it are free from such viruses.
================================================
TO SEE MESSAGE POSTING GUIDELINES:
Send a plain text email to [EMAIL PROTECTED]
In the message body, put just two words: INTRO rbase-l
================================================
TO UNSUBSCRIBE: send a plain text email to [EMAIL PROTECTED]
In the message body, put just two words: UNSUBSCRIBE rbase-l
================================================
TO SEARCH ARCHIVES:
http://www.mail-archive.com/rbase-l%40sonetmail.com/
