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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:36:22+00:00 2026-06-03T21:36:22+00:00

I have an database table set up as shown below: copy_blocks id (auto-increment int)

  • 0

I have an database table set up as shown below:

copy_blocks
id (auto-increment int)
content (text)
parent_id (int)

When a piece of copy is inserted the first time, the parent_id is set to itself. Example:

copy_blocks
id    content        parent_id
1     Hello, World   1

When that copy is updated by the user, new rows are inserted, but those row always points to the first version of the copy block.

copy_blocks
id    content         parent_id
2     Hello, World!   1
3     Heya, World!!   1

Structuring things this way allows me to either query a specific version of the content, or find the parent copy block and then look up the latest version. (In this case, version #3)

So here’s my question: Can anyone come up with a query that will always return the latest version of every content block? Ideally the query would return the results below:

id    content         parent_id
3     Heya, World!!   1

I get the feeling it would have something to do with joining against itself. I can’t think of how to do it without at least two different queries or server-side code.

  • 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-03T21:36:24+00:00Added an answer on June 3, 2026 at 9:36 pm

    One more option:

    SELECT 
          c.*
    FROM 
            ( SELECT parent_id
                   , MAX(id) AS id
              FROM copy_blocks
              GROUP BY parent_id
            ) AS dc
        JOIN
            copy_blocks AS c
          ON 
            (c.parent_id, c.id) = (dc.parent_id, dc.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system set up to lock certain content in a database table
I have a SQL database that has a table with a field set to
I have three tables as shown below Emp ---- empID int empName deptID empDetails
I have set of records in a database table lets call it Components Table
I have an SQL database with a set of tables that have Unique Id's.
If you have a set of tables in the database that strictly consist of
I have a MySQL database set-up in a hierarchy style. There are 4 tables
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
I have one database table which contains 8 columns. One of the columns is

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.