SQL 如何通过Sql Query获取Sqlite中表格的第一行/第一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5408201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get first/top row of the table in Sqlite via Sql Query
提问by Omayr
I need to fetch the first/top row of a table in a Sqlite database.
我需要获取 Sqlite 数据库中表的第一行/第一行。
But my program throws an SQLException "Sqlite Syntax Error: Syntax error near '1' " for the query that I am using:
但是我的程序为我正在使用的查询抛出 SQLException "Sqlite Syntax Error: Syntax error near '1' ":
SELECT TOP 1 *
FROM SAMPLE_TABLE
That I guess is a syntax particularly for MS SQL SERVER and MS ACCESS. Right now I am using.
我猜这是一种特别适用于 MS SQL SERVER 和 MS ACCESS 的语法。现在我正在使用。
SELECT *
FROM SAMPLE_TABLE
LIMIT 1
What is the best solution for this problem?
这个问题的最佳解决方案是什么?
回答by Achim
Use the following query:
使用以下查询:
SELECT * FROM SAMPLE_TABLE ORDER BY ROWID ASC LIMIT 1
Note: Sqlite's row id references are detailed here.
回答by Jordan Parmer
LIMIT 1is what you want. Just keep in mind this returns the first record in the result set regardless of order (unless you specify an orderclause in an outer query).
LIMIT 1是你想要的。请记住,无论顺序如何,这都会返回结果集中的第一条记录(除非您order在外部查询中指定子句)。

