Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to solve this SQL Select?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01099608
Message ID:
01099651
Views:
12
Yes,
That's why I use LEFT join :-), Becuase I need ALL records from my main table no metter if there are matching records in both other tables. And that's why I use SUM(NVL(Tbl.SumV,00000.00))

>>
>>
>>CREATE TABLE Main (Id I, Tabl2FK I, Tabl3FK I)
>>INSERT INTO Main VALUES (1,1,2)
>>INSERT INTO Main (Id, Tabl3FK) VALUES (1,3)
>>
>>CREATE TABLE Tbl2 (PK I, SumV N(10,2))
>>INSERT INTO Tbl2 VALUES (1,200)
>>
>>CREATE TABLE Tbl3 (PK I, SumV N(10,2))
>>INSERT INTO Tbl3 VALUES (2,200)
>>INSERT INTO Tbl3 VALUES (3,400)
>>
>>SELECT Main.Id, SUM(NVL(Tbl2.SumV,cast(0 as N(10,2))) AS Sum2,;
>>                SUM(NVL(Tbl3.SumV,cast(0 as N(10,2))) AS Sum3;
>>FROM Main;
>>LEFT JOIN Tbl2 ON Main.Tabl2FK = Tbl2.PK;
>>LEFT JOIN Tbl3 ON Main.Tabl3FK = Tbl3.PK;
>>GROUP BY Main.Id;
>>INTO CURSOR test
>>BROWSE NORMAL
>>
>
>If you change your LEFT JOIN with just JOIN you will see that the result changes.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform