two statments - same result ????

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Syl

    two statments - same result ????

    Hello! Can someone verify this for me please.

    Should these 2 statments return the same result ? The 2nd one is the
    original, the first one is my re-write. Thanks :

    SELECT orders_status, paypalipn_txn . *
    FROM orders
    INNER JOIN paypalipn_txn ON item_number = orders_id
    WHERE customers_id = 4417
    ORDER BY date_purchased DESC LIMIT 1

    and :

    SELECT o.orders_status ,p.*
    FROM orders o
    LEFT JOIN paypalipn_txn p on p.item_number = o.orders_id
    AND o.customers_id = 4417 order by o.date_purchase d desc limit 1

  • petersprc

    #2
    Re: two statments - same result ????

    It doesn't appear to be the same...

    The INNER JOIN will return only orders that have a corresponding
    paypalipn_txn record and belong to customer 4417.

    The original LEFT JOIN returns all orders that belong to customer 4417.
    If there's a paypalipn_txn record matching the join criteria, those
    fields will be filled in, otherwise they will appear as NULL.

    Some more info:




    Syl wrote:
    Hello! Can someone verify this for me please.
    >
    Should these 2 statments return the same result ? The 2nd one is the
    original, the first one is my re-write. Thanks :
    >
    SELECT orders_status, paypalipn_txn . *
    FROM orders
    INNER JOIN paypalipn_txn ON item_number = orders_id
    WHERE customers_id = 4417
    ORDER BY date_purchased DESC LIMIT 1
    >
    and :
    >
    SELECT o.orders_status ,p.*
    FROM orders o
    LEFT JOIN paypalipn_txn p on p.item_number = o.orders_id
    AND o.customers_id = 4417 order by o.date_purchase d desc limit 1

    Comment

    Working...