android mysql 查询数据库_Android的数据库查询

bd96500e110b49cbb3cd949968f18be7.png

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

It looks similar to this:

1 Tom group1

2 Sam group1

3 Ted group2

4 Jerry group3

5 Me 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);

}

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

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

Thanks in advance.

解决方案

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值