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

后端 未结 3 880
栀梦
栀梦 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:49

    This is a typical "JOIN" scenario where you have a one-to-many relationship between Users and Posts.

    Here is an example of a query that would display all users and their posts:

    SELECT u.User_ID, u.Name, p.Time, p.Message
    FROM Users u INNER JOIN Posts p ON u.User_ID = p.User_ID
    

    This will produce a resultset with four columns. Each "Tweet" will be displayed with its related User record. The 'u.' and 'p.' syntax are table aliases used to make the query easier to read.

提交回复
热议问题