T
|
thesofa 9/28/2006 |
I am not sure, but I think you need to change the inner join to a left join. |
D
|
Dale author 9/28/2006 |
Hi thesofa, |
D
|
Dale author 9/29/2006 |
Well I tried LEFT JOIN, same result, I tried RIGHT JOIN, same result. Both of these ran noticeably slower. The INNER JOIN was the fast. All returned the same result. |
T
|
thesofa 9/30/2006 |
Hi FROM ((((`detentions` Inner Join `pupils` ON (`pupils`.`idPupil` = `detentions`.`detainee`)) Inner Join `reasons` ON (`reasons`.`idReason` = `detentions`.`reason`)) Inner Join `staff` ON (`staff`.`userid` = `detentions`.`donor`)) Inner Join `dept` ON (`dept`.`idDept` = `detentions`.`department`)) Inner Join `sessions` ON `sessions`.`sess_id` = `detentions`.`sess`
WHERE (`customer`.`status_id` =2 AND `purchases`.`purchase_date` <= now() AND `payments`.`payment_date` <= now() )
WHERE ((`customer`.`status_id` =2) AND( `purchases`.`purchase_date` <= now()) AND (`payments`.`payment_date` <= now()) )
|
Alexey 10/2/2006 | |
Dale, SELECT `customer`.`customer_id` , `customer`.`name` , (select SUM(total) from purchases where customer_id = `customer`.`customer_id` and purchase_date <= now() ) as SUM_purchases, (select SUM(amount) from payments where customer_id = `customer`.`customer_id` and payment_date <= now()) as SUM_payments, (select SUM(total) from purchases where customer_id = `customer`.`customer_id` and purchase_date <= now()) - (select SUM(amount) from payments where customer_id = `customer`.`customer_id` and payment_date <= now()) as SUM_owing FROM `customer` WHERE `customer`.`status_id` =2
|
D
|
Dale author 10/2/2006 |
Thanks for the responses. I will try them and see if I can get over this issue. |
T
|
thesofa 10/2/2006 |
Just as a by the way, I find using something like Navicat or PHPMyadmin allows easy query building and testing, so much easier than trying to work each one out and then bug hunting with a complex set of sub queries. |