Click to See Complete Forum and Search --> : LEFT JOIN Optimisation!


dai.hop
08-03-2009, 07:36 AM
Hi all,

I have the following query:

SELECT orders.*, order_lines.*
FROM orders
WHERE DATE(orders.timestamp) BETWEEN '2009-04-01' AND '2009-06-30'
LEFT JOIN order_lines
ON orders.txn_id = order_lines.transaction_id
ORDER BY orders.timestamp ASC

I can't see anything wrong with the syntax however whenever I execute it I get a 500 Internal Server Error back from phpMyAdmin.

Firstly, is the syntax of this query correct?

Secondly, can it be optimized to perform correctly?

Thanks!

dai.hop

triassic
08-04-2009, 05:02 PM
I think the JOIN has to come before the WHERE.

NogDog
08-04-2009, 05:50 PM
I think the JOIN has to come before the WHERE.

Yes, the WHERE should be the last thing before the ORDER BY in that query.