Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:40:03+00:00 2026-05-23T00:40:03+00:00

I have three tables: posts id post_id user_id comments id post_id comment_id user_id deleted

  • 0

I have three tables:

posts

  • id
  • post_id
  • user_id

comments

  • id
  • post_id
  • comment_id
  • user_id
  • deleted

replies

  • id
  • post_id
  • reply_id
  • user_id
  • deleted

I am trying to get all comments and replies from each post.post_id with post.user_id=x.

I tried:

    SELECT *
    FROM posts AS p
    INNER JOIN comments as c
    ON c.comment_id=p.post_id
    INNER JOIN replies as r
    ON r.reply_id=p.post_id
    WHERE
    p.user_id='x'

which returns 0…


The solution was

SELECT *
FROM POSTS A
LEFT JOIN COMMENTS B ON A.POST_ID=B.COMMENT_ID
LEFT JOIN REPLIES C ON A.POST_ID=C.REPLY_ID
WHERE A.USER_ID='X'

So if I add a deleted column on the comments and replies tables, how can I check if the comment or reply I am getting is not deleted?

I tried adding after A.USER_ID='X' && B.deleted='0' && C.deleted='0'

But it returns 0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:40:04+00:00Added an answer on May 23, 2026 at 12:40 am

    You’re missing a key relationship in your model. You need to have a column in replies and comments for post_id, and then join the tables on post_id.

    Once you’ve made this change, then your query would look like this:

    SELECT c.*, r.* 
    FROM posts p
    INNER JOIN comments c ON p.id=c.post_id
    INNER JOIN replies r ON p.id=r.post_id
    WHERE p.user_id=$user_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables: products (product_id, title) comments (comment_id, product_id, user_id, comment, post_date) bookmarks
I have three tables setup: POSTS, DISCUSSIONS, and COMMENTS. The layout is as follows:
I have three tables: Post, Attachment, and Media. Posts have Attachments, and Attachments have
I basically have three tables, posts, images and postimages (this simply contains the ids
I have three tables underlying a blog: one for users, one for comments and
I have a table posts with columns post_id , user_id , post . When
I'm trying to show wall posts that all users have made on a specific
I have three tables: tbl_tag tbl_post tbl_post_tag(post_id, tag_id) tbl_users . Each Post has multiple
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables tag , page , pagetag With the data below page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.