DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: duplicates

  1. #1
    Join Date
    Feb 2005
    Posts
    28

    duplicates

    is there a way to pick the latest and greatest among the duplicates.This is a reference table so we will see multiple orderids


    select orderid,product,orderdate from orders table;

    1234 --abc--05-APR-2005 11:30:28
    1234 -- abc --05-APR-2005 11:15:34

    in the above is thier easer way i can pick the orderid based on latest orderdate.In the above i need to pick the following row
    1234 --abc--05-APR-2005 11:30:28

    Some times i have 10 + rows for every orderid.

    please let me know

    Thanks Raj

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166

    Re: duplicates

    Originally posted by raj123
    is there a way to pick the latest and greatest among the duplicates.This is a reference table so we will see multiple orderids


    select orderid,product,orderdate from orders table;

    1234 --abc--05-APR-2005 11:30:28
    1234 -- abc --05-APR-2005 11:15:34

    in the above is thier easer way i can pick the orderid based on latest orderdate.In the above i need to pick the following row
    1234 --abc--05-APR-2005 11:30:28

    Some times i have 10 + rows for every orderid.

    please let me know

    Thanks Raj
    What about something like this?

    Code:
    SELECT orders_table.orderid, 
           orders_table.product,
           orders_table.orderdate 
      FROM orders_table
     INNER JOIN
         ( SELECT orderid, MAX(orderdate) orderdate
             FROM orders_table
            GROUP BY orderid ) ot
        ON ot.orderid    = orders_table.orderid   AND
           ot.orderdate  = orders_table.orderdate;
    btw why do you have so many duplicates?

  3. #3
    Join Date
    Feb 2005
    Posts
    28
    hi ,
    thanks for the help .will try

    i have one other coulmn in the same table , where the customer can do update then it goes to different stage

    also this table has one other unique row

Posting Permissions

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


Click Here to Expand Forum to Full Width