我需要获取 Sqlite 数据库中表的第一行/第一行。
但是我的程序对我正在使用的查询抛出一个 SQLException“ Sqlite 语法错误: 语法错误靠近’1’”:
SELECT TOP 1 * FROM SAMPLE_TABLE
我猜测这是一种语法,特别适用于 MSSQLSERVER 和 MSACCESS。
SELECT * FROM SAMPLE_TABLE LIMIT 1
解决这个问题的最好办法是什么?
LIMIT 1 is what you want. Just keep in mind this returns the first record in the result set regardless of order (unless you specify an order clause in an outer query).
LIMIT 1
order
Use the following query:
SELECT * FROM SAMPLE_TABLE ORDER BY ROWID ASC LIMIT 1
Note: Sqlite's row id references are detailed here.