在Access中使用SQL随机选择一行 [英] Randomly Select a Row with SQL in Access
问题描述
我有一个带有一些表的小型访问数据库.我正在尝试在Access中的sql设计中的代码.我只想在表中随机选择一条记录.
I have a small access database with some tables. I am trying the code in the sql design within access. I just want to randomly select a record within a table.
我创建了一个名为StateAbbreviation
的简单表.它具有两列:ID
和Abbreviation
. ID
只是一个自动编号,而Abbreviation
是状态的不同缩写.
I created a simple table called StateAbbreviation
. It has two columns: ID
and Abbreviation
. ID
is just an autonumber and Abbreviation
are different abbreviations for states.
我在这里看到了此线程.所以我尝试了
I saw this thread here. So I tried
SELECT Abbreviation
FROM STATEABBREVIATION
ORDER BY RAND()
LIMIT 1;
我在查询表达式RAND() LIMIT 1
中收到错误语法错误(缺少运算符).所以我很累RANDOM()
而不是RAND()
.同样的错误.
I get the error Syntax error (missing operator) in query expresion RAND() LIMIT 1
. So I tired RANDOM()
instead of RAND()
. Same error.
其他任何人都没有工作.我究竟做错了什么?谢谢.
None of the others worked either. What am I doing wrong? Thanks.
推荐答案
Ypercude提供了一个链接,使我可以从下面找到正确的答案:
Ypercude provided a link that led me to the right answer below:
SELECT TOP 1 ABBREVIATION
FROM STATEABBREVIATION
ORDER BY RND(ID);
请注意,对于RND(),我认为它必须是整数值/变量.
Note that for RND(), I believe that it has to be an integer value/variable.
这篇关于在Access中使用SQL随机选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!