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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:49:22  来源:igfitidea点击:

How to get first/top row of the table in Sqlite via Sql Query

sqlsqlite

提问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.

注意:Sqlite 的行 id 引用在这里详细说明

回答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在外部查询中指定子句)。