Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
3 Table SQL Join
Message
From
08/12/1999 13:46:43
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00300033
Message ID:
00300512
Views:
23
>>OOPS! Please note the addition of the Filter columns for TableB and TableC.
>>
>>The following code returns 2 rows, but I desire 5 rows (one row per row of TableA).
>>
>>
select TableA.*, TableB.*, TableC.*;
>> from TableA ;
>> Left Outer Join TableB ;
>> on TableA.Ident = TableB.Ident ;
>> and TableA.FKey = TableB.FKey ;
>> Left Outer Join TableC ;
>> on TableA.Ident = TableC.Ident ;
>> where TableB.FiltB = 1 ;
>> and TableC.FiltC = 1 ;
>> group by TableA.Ident
>>
>
>If you remove the GROUP BY you will get the 3 matching rows from TableA. Because you are applying the filter where FiltB = 1 and FiltC = 1, you are never going to get all 5 records from A. Your query is returning exactly what you are asking for. If you want all 5 records you have to remove the filter clause and put in GROUP BY TableA.Ident, TableA.FKey.
select TableA.*, TableB.*, TableC.*;
 from TableA ;
 Left Outer Join TableB ;
 on TableA.Ident = TableB.Ident ;
 and TableA.FKey = TableB.FKey ;
 Left Outer Join TableC ;
 on TableA.Ident = TableC.Ident ;
 having (isnull(TableB.FiltB) = 1 or TableB.FiltB);
 and (isnull(TableB.FiltC) or TableB.FiltC = 1) 
Gives the desired result at the cost of a Cartesian explosion that the having clause must filter. Is there a way to get the filtering done in the join and still get all five rows?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform