[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problems with left joins.
Oliver,
I tried the following query;
SELECT table1.*, table2.*, table3.*
FROM table1 LEFT JOIN table2 ON table1.fkey1 = table2.id
LEFT JOIN table3 ON table1.fkey2 = table3.id
And it worked fine for me. This should be a valid outer join syntax.
Toby.
Oliver Jones wrote:
> I think I've answered my own question. WOuld thgis be the correct way
> of doing things, it seems to work:
>
> SELECT table1.id, table2.id AS fkey1, table3.id AS fkey2
> FROM
> table1 LEFT JOIN table2 ON table1.fkey1 = table2.id
> LEFT JOIN table3 ON table1.fkey2 = table3.id
>
> Regards
>
> On Fri, 2003-01-03 at 20:31, Oliver Jones wrote:
>
>
>>I'm having a bit of trouble sorting out a query.
>>
>>I have three tables, table1 has a foreign key references into the
>>others. However it is possible for that foreign key to be null. But
>>I want to do a join across the tables. If I do a traditional SELECT
>>in the form of:
>>
>>SELECT table1.*, table2.*, table3.*
>>FROM table1, table2, table3
>>WHERE table1.fkey1 = table2.id
>>AND table1.fkey2 = table3.id;
>>
>>When table1.fkey1 or table1.fkey2 is null no record appears. This is
>>to be expected. I understand this.
>>
>>I'm used to solving this problem with MySQL like this:
>>
>>SELECT table1.*, table2.*, table3.*
>>FROM table1,
>>LEFT JOIN table2 ON table1.fkey1 = table2.id
>>LEFT JOIN table3 ON table1.fkey2 = table3.id;
>>
>>However McKoi has a different syntax. It requires a table reference
>>before the "LEFT JOIN". I don't know what to put there. If I specify
>>table1 McKoi errors about duplicate table references.
>>
>>How do I solve my problem?
>>
>>Regards
>>--
>>Oliver Jones > Senior Software Engineer > Deeper Design Limited.
>>oliver@deeper.co.nz > www.deeperdesign.com > +64 (21) 41-2238