TOP 1 在 sql 查询中是什么意思? [英] What does TOP 1 mean in an sql query?

查看:78
本文介绍了TOP 1 在 sql 查询中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TOP 1 在 sql 查询中是什么意思?

What does TOP 1 mean in an sql query?

SELECT TOP 1 RequestId 
FROM PublisherRequests

推荐答案

示例中的查询将返回表 PublisherRequests 中的第一个 RequestID.
没有 Order By 子句的结果的顺序是任意的.因此,您的示例将返回任意 RequestID(即 RequestID 的任意排序列表中的第一个 RequestID).
您可以通过定义 Order By 来更改顺序.
比如获取最后输入的ID,可以这样写

The query in the example will return the first RequestID from the table PublisherRequests.
The order of the results without an Order By clause is arbitrary. So, your example will return an arbitrary RequestID (i.e. the first RequestID in an arbitrarily ordered list of RequestIDs).
You can change the order by defining an Order By.
For example, to get the last entered ID, you can write

Select Top 1 RequestID
From PublisherRequests
Order By RequestID Desc

更新以包含来自 @Kirtan Gor@AlexK

这篇关于TOP 1 在 sql 查询中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆