Get latest updated records

前端 未结 5 1811
旧时难觅i
旧时难觅i 2020-12-22 03:00

I have an \"Observation\" table in SQL Server 2008. This table has a locationId column for a bunch of geographic locations, a few columns for observation details and a colum

相关标签:
5条回答
  • 2020-12-22 03:05
    select a.* from observations a inner join 
    (select locationid ,max(updateddate) dates  from observations
    group by locationid) b
    on a.locationid=b.locationid
    and a.updateddate=b.dates  
    
    0 讨论(0)
  • 2020-12-22 03:06
     select * from observation where date=(select max(date) from observation)
    

    or

    select top 1 * from observation order by date desc
    
    0 讨论(0)
  • 2020-12-22 03:08

    Use the Getdate function as I used as below.

    select * from TBL_MP_QC_CustomerWiseCOA_Master  order by getdate() desc
    
    0 讨论(0)
  • 2020-12-22 03:12

    Add a column to your table with a datatype of [timestamp] execute the following code:

    select top(10) * from yourtablename order by columanname desc
    

    Note:columanname should be the column you add with a timestamp type

    0 讨论(0)
  • 2020-12-22 03:23

    Run query

    select * from Observation 
    group by location 
    order by viewdate desc
    

    Please also give the full details about table and what you want to get.

    EDIT : Backtick removed.

    0 讨论(0)
提交回复
热议问题