Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    24

    Unanswered: how to select earliest record?

    hello everyone, im trying to get the earliest record. data is below

    note_id/ doc_received_date/ bankruptcy_date/ sp_recorded_date
    2332/ 20090106<---- / 20081219/ 20090106
    2332/ 20090323/ 20081219/ 20090323
    2332/ 20090413/ 20081219/ 20090413
    2332/ 20090507/ 20081219/ 20090507


    because the bankruptcy_date date are all equal i would need to pull one record with the earliest date from the doc_received_date. The date with the arrow is the record i want. So basically i would like to show this result

    note_id/ doc_received_date/ bankruptcy_date/ sp_recorded_date
    2332 20090106 20081219 20090106

    Hope this made sense.. Thanks for you ur help

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT *
      FROM daTable
     WHERE doc_received_date =
           ( SELECT MIN(doc_received_date)
               FROM daTable
              WHERE bankruptcy_date =
                    ( SELECT MIN(bankruptcy_date)
                        FROM daTable ) )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT TOP 1 *
      FROM daTable
    ORDER
        BY bankruptcy_date
         , doc_received_date
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT COUNT(*)
      FROM skinning_methods
     WHERE item = 'cat'
    HAVING COUNT(*) > 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i lol'd, eh
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Quote Originally Posted by r937 View Post
    i lol'd, eh
    Yeah, you did.

    (hint ROW_NUMBER())
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Posting Permissions

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