开发者

Android SQLite query to prevent returning duplicate.

I have a database as follows:

_ID : SUBJECT : Topic : LectureNumber

1 : WMCC   : RF       :     1
2 : WMCC   : Fading   :     2
3 : CCN    : IP       :     1
4 : CCN    : MAC      :     2
5 : WMCC   :开发者_运维知识库 Planning :     3

I have to place the queries in a List using SimpleCursorAdaptor such that

1)at first all subjects are placed in the List only once(No duplicates), i.e. the List displays only WMCC and CCN

2)when I click on a Subject Name, a new list is displayed containing all Lectures on that subject. e.g. If I click WMCC a new list is displayed containing all lectures on WMCC.

I am actually facing the problem in achieving the first task i.e PLACING SUBJECT NAMES IN A LIST USING SimpleCursorAdaptor only once.

Thanks.


Typically, in a "normalized" relational database, you would have a separate SUBJECTS table. What you have shown above is not a "database" but a "denormalized table".

You could get the unique set of subjects from your denormalized table (let's call it LECTURES) so:

       select DISTINCT subject from LECTURES

The query to get the set of lectures for a given subject:

      select * from LECTURES where subject =  'the-subject-chosen-from-your-GUI-list'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜