有没有更好的方法来编写这个SQL查询?
问题描述:
我正在寻找返回最大的create_dt行。这工作正常,但我想知道是否有更合适的方法来做到这一点?有没有更好的方法来编写这个SQL查询?
select * from
table1
where job_no='101047'
and
create_dt in
(select max(create_dt) from
table1 where job_no='101047')
答
如何:
Select top 1 *
from table1
where job_no = '101047'
order by create_dt desc
答
您的查询将返回多个值,如果有create_dt
的多行,其中job_no = '101047'
这将更好地工作
Select top 1 * from table1
where job_no='101047'
order by create_dt desc
你不提这DB技术。 – RichardOD 2009-07-31 14:26:59
对不起,我正在使用msSQL。 – jr3 2009-07-31 14:29:53