Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL select problem with order of LEFT JOIN
Message
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
SQL select problem with order of LEFT JOIN
Environment versions
Visual FoxPro:
VFP 6 SP5
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01060396
Message ID:
01060396
Views:
55
Note that this message/problem I experience is with VFP 6 (because I don't know if it works differently in VFP 9)

I have the following SQL Select (simplified)
select MYTABLE1.FIELD1 as GROUP_ID, ;
  COUNT(DISTINCT(MYTABLE1.ORDER_NO)) as NUM_ORDS, ;
nvl(SUM(CHILD1.NUM_FIELD1),0) AS TOT_NUM1, ;
nvl(SUM(CHILD2.NUM_FIELD2*CHILD2.NUM_FIELD3),0) as TOT_NUM2, ;	
from MYTABLE1 ;
LEFT JOIN CHILD1 ON MYTABLE1.ORDER_NO = CHILD1.ORDER_NO ;
LEFT JOIN CHILD2 on MYTABLE1.ORDER_NO = CHILD2.ORDER_NO ; 	
where MYTABLE1.ORD_DATE >= ctod("01/01/2002") and MYTABLE1.ORD_DATE <= ctod("12/31/2002") 
group by GROUP_ID
The problem is that depending on the order of LEFT JOIN CHILD1 and LEFT JOIN CHILD2 I get asterisk (*) in either field TOT_NUM1 or TOT_NUM2.

Can someone explain why it works that way and possibly how to avoid it?

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Next
Reply
Map
View

Click here to load this message in the networking platform