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 6741191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:41:44+00:00 2026-05-26T11:41:44+00:00

I’m assuming that StackOverflow’s question and answer (or even FB’s wall messages) can be

  • 0

I’m assuming that StackOverflow’s question and answer (or even FB’s wall messages) can be mimicked by the following model:

TABLE: message

==================================================================
| message_id | parent_message_id | message           | timestamp |
==================================================================
| 1          | 0                 | Hi                | 100       |
| 2          | 1                 | hello             | 200       |
| 3          | 1                 | hello back to you | 300       |
| 4          | 0                 | How are you?      | 150       |
| 5          | 4                 | Good. You?        | 200       |
| 6          | 4                 | Good, too.        | 250       |
------------------------------------------------------------------

Questions:

  1. Is this a good way to do parent-child relationships for such messages? It could be split into 2 tables, but the child table would look exactly like the parent table + a foreign key. So I think one table is good enough.
  2. How do I query: get a list of all parent messages and the first 4 responses to them?
  3. How do I query: given a parent message id, get a list of the next 10 responses after the first 4?
  4. How do I query: get the last 10 messages of a particular discussion thread (similar to FB’s messages where you only see the last x-number of messages)?
  5. How do I query: get the second to the last 10 messages of a particular discussion thread (again, similar to FB’s messages when you scroll up and it shows you more of the previous messages)?

If the DB design concept is inherently wrong, please let me know.

  • 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-26T11:41:44+00:00Added an answer on May 26, 2026 at 11:41 am

    Below is the DB layout for SO.
    As you can see in the first table posts your idea is exactly what SO does.

    A query to get a question and its answers would be:

      SELECT q.body, q.otherfields
      FROM posts q
      WHERE q.id = 1234
    UNION ALL
      SELECT a.body, a.otherfields
      FROM posts a
      WHERE a.ParentId = 1234
    

    This will put the question at the top and the answers below it.

    Stackoverflow data structure:

    Posts
        Id
        PostTypeId
        AcceptedAnswerId
        ParentId
        CreationDate
        Score
        ViewCount
        Body
        OwnerUserId
        OwnerDisplayName
        LastEditorUserId
        LastEditorDisplayName
        LastEditDate
        LastActivityDate
        Title
        Tags
        AnswerCount
        CommentCount
        FavoriteCount
        ClosedDate
        CommunityOwnedDate
    Users
        Id
        Reputation
        CreationDate
        DisplayName
        LastAccessDate
        WebsiteUrl
        Location
        AboutMe
        Views
        UpVotes
        DownVotes
        EmailHash
        Age
    Comments
        Id
        PostId
        Score
        Text
        CreationDate
        UserDisplayName
        UserId
    Badges
        Id
        UserId
        Name
        Date
    PostFeedback
        Id
        PostId
        IsAnonymous
        VoteTypeId
        CreationDate
    PostHistory
        Id
        PostHistoryTypeId
        PostId
        RevisionGUID
        CreationDate
        UserId
        UserDisplayName
        Comment
        Text
    PostHistoryTypes
        Id
        Name
    PostTags
        PostId
        TagId
    PostTypes
        Id
        Name
    SuggestedEdits
        Id
        PostId
        CreationDate
        ApprovalDate
        RejectionDate
        OwnerUserId
        Comment
        Text
        Title
        Tags
        RevisionGUID
    SuggestedEditVotes
        Id
        SuggestedEditId
        UserId
        VoteTypeId
        CreationDate
        TargetUserId
        TargetRepChange
    Tags
        Id
        TagName
        Count
    TagSynonyms
        Id
        SourceTagName
        TargetTagName
        CreationDate
        OwnerUserId
        AutoRenameCount
        LastAutoRename
        Score
        ApprovedByUserId
        ApprovalDate
    Votes
        Id
        PostId
        VoteTypeId
        UserId
        CreationDate
        BountyAmount
    VoteTypes
        Id
        Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

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.