Get the latest result (new in sql)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Casper2
    New Member
    • Aug 2006
    • 2

    Get the latest result (new in sql)

    I have a huge table with multiple record for one patient but I only want the latest
    result within a year. How can I do it?

    thanks, :confused:
    Casper2
  • lipsa
    New Member
    • Aug 2006
    • 35

    #2
    hi,
    what cloumns are there in ur table,if u hv date colun then u can easily do that
    with where ...LIKE,IN clauses
    select * from <table> where <date_column> like '%yyyy%'
    Regards,
    Lipsa

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      And also use ORDER BY and LIMIT clauses to order by date (most recent first) and limit the return result to 1 record.

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        Banfa i do believe LIMIT is mysql

        I am pretty sure its TOP in sql server.

        Comment

        • iam_clint
          Recognized Expert Top Contributor
          • Jul 2006
          • 1207

          #5
          Code:
          select top 1 * from <table> where <date_column> like '%yyyy%' order by <date_column> desc
          So this should do what your looking for i would think.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by iam_clint
            Banfa i do believe LIMIT is mysql

            I am pretty sure its TOP in sql server.
            That's good to know since I am just about to start using SQL Server at work :D

            Thank You

            Comment

            Working...