Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    16

    Unanswered: Query help. newest distinct rows.

    A prices table will list the prices of products, and will be updated often.

    Prices
    id product_id qty price timestamp

    Each product ID will have multiple entry's.

    What I want to select is the newest entry's for each unique combination of 'product_id' and 'qty'.

    How do I fit max(timestamp) in with this query:
    (SELECT DISTINCT product_id, qty FROM prices)?

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT product_id
         , qty 
         , MAX(timestamp) AS latest
      FROM prices
    GROUP
        BY product_id
         , qty
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2010
    Posts
    16
    awesome, thanks!

Posting Permissions

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