For example data if i categorize data to 3 group : Attraction, City landmark, Park
id title content address category
1 GeneralPark xxxxxxxxxxx 1234road Park
2 GreatMuseum wwwwwwwwww 9877road Attraction
Look at General Park. its category is Park. and it also in Attraction category. the question is .. how can i design database? Is it possible to do like the following(put Park and Attraction in the same column):
id title content address category
1 GeneralPark xxxxxxxxxxx 1234road Park,Attraction
So, if it’s not, then how can i design database? and How should i implement this line to retrive data by category; i.e. By Attraction
public Cursor getplaces()
{
Cursor c = mDb.query(Constants.TABLE_NAME_PLACE, null, null, null, null, null, null);
return c;
}
The expect result should show only Attraction Category:
id title content address category
1 GeneralPark xxxxxxxxxxx 1234road Attraction
2 GreatMuseum wwwwwwwwww 9877road Attraction
4 Middlehigh-school ttttttttt 555road Attraction
5 ShoppingMall ssssssssss 666road Attraction
Thanks so much for your help. i’m quite new to developing. Thanks you
Don’t put two things (i.e. ‘Park,Attraction’) in one column, that is almost always a mistake. The usual way to deal with this situation is to add another table with two columns:
You’d usually make a two column primary key to avoid duplicates as well, hence the
primary keyconstraint at the bottom. A foreign key onplace_idwould be a good idea too, referential integrity saves a lot of pain, suffering, and confusion.And then, if you want to work with the categories for a place, just join to
place_categories:With this approach, your
placetable would look something like this:and the data would look something like this: