SQL Server TOP(1) with distinct
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to extract the first row I get after ordering the result by i_version_id . If I do not use TOP(2) , my query works as expected ans returns all results sorted by i_version_id. But when I add the TOP(2) (as shown below), it says that there is a syntax error near distinct . Please let me know what I am doing wrong. SELECT TOP(2) distinct(i_version_id) FROM [PaymentGateway_2006].[dbo].[merchant] WHERE dt_updated_datetime > '2013-11-11' GROUP BY i_version_id ORDER BY i_version_id; 回答1: If you're only getting the TOP 1 then distinct is