I am looking for the best way to save a set of "posts" as well as comments on these posts in SQL. Imagine a design similar to the “Wall” on Facebook, where users can post on their wall and other users can post comments. I need to be able to display all posts on the wall, as well as comments.
When I just started, I came up with a table, for example:
CREATE Table wallposts
(
id uuid NOT NULL,
posted timestamp NOT NULL,
userid uuid NOT NULL,
posterid uuid NOT NULL,
parentid uuid NOT NULL,
comment text NOT NULL
)
id is unique, parentid will be empty in the original messages and will point to id if the line is a comment on an existing post. Easily and very quickly insert new data. However, having made a choice that will bring me back:
POST 1
COMMENT 1
COMMENT 2
POST 2
COMMENT 1
COMMENT 2
, . , , , - 1 , 2 . LEFT JOIN, , , , null.
:
CREATE TABLE wallposts
(
id uuid NOT NULL,
threadposted timestamp,
posted timestamp,
...
comment text
)
, threadposted . , , "" , . :
select * from wallposts order by threadposted, posted;
, . , , . "" , 1/1000 . threadposted , , , . , , , , . .
. node v-left v-right. "", , . , - , . , . , , . .
, , , . , , , , , . , .
, . , . "" , node . , node , , node . , O (n). , , HTML. , ; , , , . , , , .
, SQL, , , JOINS UNIONS -, .