如何在SQL Server 2005中使用LIMIT关键字? [英] How to use LIMIT keyword in SQL Server 2005?
本文介绍了如何在SQL Server 2005中使用LIMIT关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在>的表中找到了一种从表中选择随机行的方法这篇文章.建议使用以下查询:
I have found a way to select random rows from a table in this post. A suggestion is to use the following query:
SELECT * FROM employee ORDER BY RAND() LIMIT 1
但是当我在MS SQL 2005中运行此查询时,出现以下错误消息
But when I run this query in MS SQL 2005, I get the following error message
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'LIMIT'.
谁能告诉我我哪里错了? MS SQL不支持LIMIT吗?如果是这样,那我该怎么办?
Can anyone tell me where am I wrong? Doesn't MS SQL support LIMIT? If so, then how can I do this?
推荐答案
如果您看一下SQL Server联机丛书中的SELECT语句,那么您会发现可以使用TOP关键字来限制结果集. /p>
If you take a look at the SELECT statement in SQL Server Books Online, then you'll see that you can limit the resultset by using the TOP keyword.
SELECT TOP 1 * FROM employee
这篇关于如何在SQL Server 2005中使用LIMIT关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文