dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: LEFT JOIN Optimisation!

  1. #1
    Join Date
    Aug 2006
    Posts
    126

    LEFT JOIN Optimisation!

    Hi all,

    I have the following query:

    Code:
    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

  2. #2
    Join Date
    Jun 2009
    Posts
    36
    I think the JOIN has to come before the WHERE.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,309
    Quote Originally Posted by triassic View Post
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles