ChicagoKiwi wrote:
Otis wrote:
So my question to ChicagoKiwi is: could you give a query which works and which illustrates the structure you want? The place of the ON clause isn't important anyway, it's the order in which left/right are specified in the relationcollection.
Hypothetical example: I'm trying to return a list of all customers and the number of "rush" subprojects they're associated with.
This works (and I think it's ANSI standard), but I'm not sure how to generate it from LLBL.
select customer_name, count(distinct subproject_customer.subproject_id)
from customer
left join (subproject_customer
inner join subproject on subproject_customer.subproject_id = subproject.subproject_id and subproject.rush = 'N')
on customer.cmf = subproject_customer.cmf
group by customer_name
This doesn't work (it only returns customers that have a subproject) and is in the form that LLBL generates:
select customer_name, count(distinct subproject_customer.subproject_id)
from ((customer
left join subproject_customer on customer.cmf = subproject_customer.cmf)
inner join subproject on subproject_customer.subproject_id = subproject.subproject_id and subproject.rush = 'N')
group by customer_name
Ok, so the INNER join limits the rows, and if that's the last join performed, (joins are done from inner to outer so (a join b) join c will first join a with b and then with c), no rows are returned.
You can reword your working query as:
select customer_name, count(distinct subproject_customer.subproject_id)
from
(
subproject_customer inner join subproject
on subproject_customer.subproject_id = subproject.subproject_id and subproject.rush = 'N'
) RIGHT JOIN customer
on customer.cmf = subproject_customer.cmf
group by customer_name
so you have to change the order in which you add the relations to the relationcollection