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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:17:47+00:00 2026-06-11T14:17:47+00:00

I was trying to teach myself something new and having a look at the

  • 0

I was trying to teach myself something new and having a look at the way WordPress structures it’s tables to work with revisions.

The structure is (sorta) as follows:

+----+------------+---------------------+------------+-----------------+-------------+
| ID | post_title |      post_date      | post_name  |   post_content  | post_parent |
+----+------------+---------------------+------------+-----------------+-------------+
|  1 | Foo        | 2012-09-20 10:00:00 | Foo        | Bar             |           0 |
|  2 | Arrrrr     | 2012-09-20 10:05:00 | Arrrr      | Pirates!        |           0 |
|  3 | Arrrrrr    | 2012-09-20 10:06:00 | revision-1 | Argh pirates    |           2 |
|  4 | Arrrrrr    | 2012-09-20 10:06:00 | revision-2 | Argh piratessss |           2 |
+----+------------+---------------------+------------+-----------------+-------------+

Now, I’d like to make a query that gives me ONLY the parent rows (Foo and Arrrr) with their ID’s, BUT with their revised content.

I came up with following query:

SELECT original.ID, revision.post_title, revision.post_content, revision.post_name FROM wp_posts AS original
INNER JOIN wp_posts AS revision ON original.ID = revision.post_parent
WHERE original.post_status = 'publish'
AND original.post_parent = 0
ORDER BY original.ID, revision.ID DESC

This gives me following result:

+----+------------+---------------------+------------+-----------------+-------------+
| ID | post_title |      post_date      | post_name  |   post_content  | post_parent |
+----+------------+---------------------+------------+-----------------+-------------+
|  1 | Foo        | 2012-09-20 10:00:00 | Foo        | Bar             |           0 |
|  2 | Arrrrrr    | 2012-09-20 10:06:00 | revision-2 | Argh piratessss |           2 |
|  2 | Arrrrrr    | 2012-09-20 10:06:00 | revision-1 | Argh pirates    |           2 |
|  2 | Arrrrr     | 2012-09-20 10:05:00 | Arrrr      | Pirates!        |           0 |
+----+------------+---------------------+------------+-----------------+-------------+

But I’d like to further reduce it to:

+----+------------+---------------------+------------+-----------------+-------------+
| ID | post_title |      post_date      | post_name  |   post_content  | post_parent |
+----+------------+---------------------+------------+-----------------+-------------+
|  1 | Foo        | 2012-09-20 10:00:00 | Foo        | Bar             |           0 |
|  2 | Arrrrrr    | 2012-09-20 10:06:00 | revision-2 | Argh piratessss |           2 |
+----+------------+---------------------+------------+-----------------+-------------+

I’ve tried adding DISTINCT to the SELECT, and adding GROUP BY original.ID but both didn’t give me the desired result.

  • 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-11T14:17:49+00:00Added an answer on June 11, 2026 at 2:17 pm

    While you can’t distinguish different revisions of one topic for each other except date you can do the following:

    select * from wp_posts p join
                    (
                        select max(post_date) as max_dtm, id
                        from wp_posts
                        group by if(post_parent = 0, id, post_parent)
                    ) v on p.id = v.id and p.post_date = v.max_dtm; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to teach myself Boost Unit, but I am having some problems when
I'm trying to teach myself C++, and one of the traditional new language exercises
I'm new to the whole Action Script / Flash world...but trying to teach myself
I'm trying to teach myself but am struggling with how to store something like
So Im trying to teach myself rails and having some trouble with figuring out
I'm trying to teach myself some basic jquery and am having trouble with an
I'm trying to teach myself C# but am having trouble with this code: using
I'm trying to teach myself C by coding up a linked list. I'm new
Disclaimer: I'm relatively new to iOS programming, and am trying to teach myself the
Trying to teach myself Rails and have come across something that was easy in

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.