Sorry for the ridiculous question title. I didn’t know how to generalize it.
I need a list of comments that occur after my comments left on a post I did not create.
I’m using postgres. My post table structure:
CREATE TABLE posts (
id integer NOT NULL,
parent_id integer DEFAULT (-1),
msg character varying(140),
user_id integer,
create_dte numeric(10,0) DEFAULT 0
);
There can only be one level of comments. Original posts
have a parent_id of -1. Comments have a parent_id of an original post’s id.
I can get my comments on posts I didn’t create:
select p1.id, p1.msg
from posts p1
where p1.user_id = MY_USER_ID
and p1.parent_id in (
select p2.id
from posts p2
where p2.parent_id = -1
and p2.user_id != MY_USER_ID)
Can someone give me a hint on how to select the posts that have the same parent_id
and a greater create_dte?
I used the answer from @podiluska above as a jumping-off point for this solution: