Android的数据库查询 [英] Android database query

查看:481
本文介绍了Android的数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表3列:_id,名称,组名

I have a database table with 3 columns: _id, name, groupName

它看起来类似于这样:

1汤1组

2萨姆组1

3特德组2

4杰里GROUP3

4 Jerry group3

5我GROUP3

我要查询数据库表的组名。我曾尝试这样的:

I want to query the database table for groupName. I have tried this:

public Cursor getAllGroups() 
{
      return db.query(DATABASE_TABLE_1, new String[] {KEY_GROUP}, 
            null, null, null, null, null);
}

这将返回沿光标:(1组,组1,组2,组3,组3)。

And this returns a cursor along: (group1, group1, group2, group3, group3).

有没有办法得到的只有独特的群体? (所以,我最终会与光标一起:(1组,组2,组3)

Is there a way to get only unique groups? (So I would end up with a cursor along: (group1, group2, group3)

先谢谢了。

推荐答案

我认为你需要使用原始的SQL查询使用DISTINCT关键字。粗糙code会是这样的:

I think you need use raw SQL query with DISTINCT keyword. Rough code would be something like:

db.rawQuery("select distinct groupName from "+DATABASE_TABLE_1, null);

下面是关于关键字 HTTP://www.sql- tutorial.com/sql-distinct-sql-tutorial/

这篇关于Android的数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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