0

I have data in my sqlite table like the following

here is the my table description and fields

    coffeeID;
category;
sub_Category;
content_Type;
content_Title;
content_Description;
content_Id;
publisher;
content_Source;
update_date_time;

and here is the code where i am now getting all values but i want unique values.

       const char *sql = "select * from category";


    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

        while(sqlite3_step(selectstmt) == SQLITE_ROW) {

            NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
            Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
            coffeeObj.category=sqlite3_column_int(selectstmt,1);
            coffeeObj.sub_Category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
            coffeeObj.content_Type = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
            coffeeObj.content_Title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,4)];

            coffeeObj.publisher = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
            coffeeObj.content_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
            coffeeObj.content_Id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
            coffeeObj.content_Source = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)];

            int count=[appDelegate.coffeeArray count];

            NSLog(@"count is beofore getting values %d",count);



            [appDelegate.coffeeArray addObject:coffeeObj];



            int countone=[appDelegate.coffeeArray count];

            NSLog(@"count is after getting values %d",countone);

            [coffeeObj release];
        }
    }
}

I want that if it has two same sub categories then it may show only one like mean only unique records not the categories with same name repeated.

4

1 回答 1

0

You can use Group by in SQL Query

"Select * From category GROUP BY category"

You can group by any column

于 2013-04-16T10:31:35.430 回答