仅查询表中的第一个数据 [英] Query only the first data from a table
本文介绍了仅查询表中的第一个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试仅查询表中的第一个数据.
I'm trying to query only the first data from the table.
Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null",
null, null, null, null);
有人可以告诉我如何实现从表中仅检索第一个数据的查询吗?
Could somebody tell me how to implement a query where only the first data is retrieved from a table?
解决方案
我想我已经解决了答案:
I think I solved the answer:
Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null",
null, null, null, null , "1");
我首先使用了limit 1
,但是应用程序崩溃了.仅当我将数字作为String
传递时,它才有效.当我们使用limit参数时,查询有8个参数.
I used limit 1
first, but the application crashed. Only if I pass the number as a String
will it work. The query has 8 parameters while we're using the limit parameter.
推荐答案
limit 1
来自文档:
public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
因此,将您的最后一个参数设置为限制1".
so, put your last argument to be "limit 1".
Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null,
null, null, null, "limit 1");
这篇关于仅查询表中的第一个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文