Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select with multiple joins
Message
From
23/08/1999 12:56:08
Oleg Khvalin
The Sutherland Group Ltd
Rochester, New York, United States
 
 
To
20/08/1999 17:52:48
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00255950
Message ID:
00256657
Views:
23
>Hi Erik,
>
>>SELECT ARCust.*, Address1.Address, Address2.Address FROM ARCust, Address Address1, Address Address2 WHERE ARCust.AddressID1 = Address1.ID and ARCust.AddressID2 = Address2.ID
>
>This won't work, saddly. This will eliminate records which don't have the optional shipto address, where a left join leaves an unmatched in. I was hoping to do something like:
>
>
select a.arno, b.lname, c.lname as shiplname;
>	from ar a left join address b on a.id_addr = b.id_addr,;
>	ar a left join address c on a.id_ship=c.id_addr ;
>	into cursor temp
>
>whcih doesnt work, so I
>
>select a.arno, b.lname, c.lname as shiplname;
>	from ar a left join address b on a.id_addr = b.id_addr, address c ;
>	where a.id_ship = c.id_addr;
>	union (select a.arno, b.lname, c.lname as shiplname;
>	from ar a left join address c on a.id_ship=c.id_addr, ;
>	address b where a.id_ship = 0 and a.id_addr = b.id_addr);
>	into cursor temp
instead. I don't like and will keep looking however. There are few times when this "Optional Foreign Key" get in my way so I won't need to do this to often. Thanks for your help, though!

Hi,Mike
I guess your outer join will work with only minor changes: don't repeate AR table after 1-st join:
select a.arno, b.lname, c.lname as shiplname;
from ar a ;
left join address b on a.id_addr = b.id_addr ;
left join address c on a.id_ship=c.id_addr ;
into cursor temp

HTH
Oleg
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform