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

  • Home
  • SEARCH
  • 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 8465619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:06:10+00:00 2026-06-10T15:06:10+00:00

I have two tables post Table post_id post_name post_summary date post_reply Table parent_id post_id

  • 0

I have two tables

post Table
 post_id
 post_name
 post_summary
 date

post_reply Table
 parent_id
 post_id

So what I am doing is I inset a new post detail in post table and if there is any reply for that post then I put all the detail in post table itself and also stores the main post id as parent_id and replyed post id as post_id in post_reply.

Now I want to fetch all the posts and their reply under the main post if there is any and want to display the same on my jsp page.

I can’t write a single query to fetch these details. I can do it by first fetching all the post whose ids are not in post_reply and then loop on all post and then fetch the main post and replied post one by one.

I just want to fetch all these in one query. Is this possible? I am using mysql as database and using spring mvc with mybatis. So I am fecthing the whole list and putting it in my model attribute and display it on jsp page.

If someone can suggested me a better way of achieving this like changing my database structure or any other solution then that would be great.

  • 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-06-10T15:06:11+00:00Added an answer on June 10, 2026 at 3:06 pm

    table post

    +---------+-------+---------+
    | post_id | post  | comment |
    +---------+-------+---------+
    |       1 | kjasd | ajsdh   |
    |       2 | abc   | dfgdfg  |
    |       3 | ashdf | NULL    |
    +---------+-------+---------+
    

    table post_reply

    +-----------+---------+
    | parent_id | post_id |
    +-----------+---------+
    |         1 |       2 |
    +-----------+---------+
    

    Use this query it is working:

    select *from post where post_id=1 or post_id in (select post_id from post_reply where parent_id=1);
    

    It will return the reply with parent post and parent post only if there is no reply..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables. Table 1. ======== id post -------- Table 2. ======== id
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two table named: Blog for displaying blogs post and comments for displaying
I have two table posts & categories post_id | post_title | post_content | post_cat
I have two tables called 'events' and 'topics' each table can have many comments.
I have two tables sturctured like so: Posts Table id content Meta Table id
I have a two tables, Post and categories, Post have category_id I can get

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.