How implement one-to-many objects database in sqlite for android

后端 未结 3 878
栀梦
栀梦 2021-01-02 03:59

I\'m quite new to SQLite and SQL and I am struggling with how to approach the following:

My app will display a list of community members. I

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 04:41

    You need to have two tables:

    1.Users

    USER_ID | NAME

    2.TWEETS

    USER_ID | TIME | MESSAGE

    Now for the explanation:

    Table 1 is represents the users, there is all the data about the user, like name, phone, address etc.

    Table 2 is for all the tweets of all the users, and there is a column that connects between user and his tweet. In table 2 USER_ID is foreign key, that points to exactly one row in the users table.

    To get all the tweets for one user, you can write the next query:

    Select TWEETS.MESSAGE, TWEETS.TIME
    from Users, TWEETS
    where Users.USER_ID = TWEETS.USER_ID
    and Users.NAME = "Pierre";
    

提交回复
热议问题