在android sqlite中选择不同的值 [英] select distinct value in android sqlite

查看:34
本文介绍了在android sqlite中选择不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 android 中运行以下原始查询,它似乎不起作用

I try to run the following raw query in android, it seems not work

String query ="SELECT DISTINCT category FROM event";
Cursor  cursor = mDb.rawQuery(query, null);
if (cursor != null) {
     cursor.moveToFirst();
}
return cursor; 

所以我决定在android中使用query()方法,类似于

so I decide to use the query() method in android which are something like

Cursor mCursor = mDb.query(EVENT_TABLE, new String[] {KEY_ROWID, KEY_CAT}, null, null,null,null, null)

谁能告诉我如何选择使用 query() 而不是 rawquery 的不同类别,任何帮助将不胜感激!

Can anyone show me how to select the distinct category for using query() instead of rawquery please, any help will be greatly appreciated!

推荐答案

您可以使用 这个方法:

public Cursor query (boolean distinct, String table, 
                     String[] columns, String selection, 
                     String[] selectionArgs, String groupBy, 
                     String having, String orderBy, String limit)

这里的第一个参数指定是否使用 distinct .

Here first argument specifies whether to use distinct or not.

这篇关于在android sqlite中选择不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆