作为起点,我有以下查询。我知道它可以工作并产生我正在寻找的结果,但是否可以以更快/更有效的方式完成,因为它可能会处理大量数据以找到我想要返回的内容。
(下例中的ID为自增PK字段)
select x, y, z
from table
where id = (select max(id) from table where z = someValue)
我会建议:
select top (1) x, y, x
from table
where z = somevalue
order by id desc;
为了提高性能,您需要在(z, id)
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句