2009-07-31 147 views
3

我正在寻找返回最大的create_dt行。这工作正常,但我想知道是否有更合适的方法来做到这一点?有没有更好的方法来编写这个SQL查询?

select * from 
table1 
where job_no='101047' 
and 
create_dt in 
    (select max(create_dt) from  
     table1 where job_no='101047') 
+2

你不提这DB技术。 – RichardOD 2009-07-31 14:26:59

+1

对不起,我正在使用msSQL。 – jr3 2009-07-31 14:29:53

回答

15

如何:

Select top 1 * 
from table1 
where job_no = '101047' 
order by create_dt desc 
4

您的查询将返回多个值,如果有create_dt
的多行,其中job_no = '101047'

这将更好地工作

Select top 1 * from table1 
where job_no='101047' 
order by create_dt desc 
相关问题