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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:51:11+00:00 2026-06-18T15:51:11+00:00

I have something like this: ID | post_author | post_date | … | post_title

  • 0

I have something like this:

ID | post_author | post_date | ... | post_title | post_status | ... | post_type
-------------------------------------------------------------------------------
1  | 1           | 2007-08-11| ... | A          | publish     | ... | post
2  | 3           | 2007-08-12| ... | B          | publish     | ... | post
3  | 1           | 2007-08-12| ... | C          | publish     | ... | post
4  | 1           | 2007-08-13| ... | D          | publish     | ... | post
5  | 3           | 2007-08-13| ... | E          | publish     | ... | post

What I like to do is to get the amount of posts by user and the title and ID of the last post. Based on above data the result should be that:

AuthorID | TotalPosts | PostID | PostTitle
------------------------------------------
1        | 3          | 5      | E
3        | 2          | 4      | D

What I have tried is this:

SELECT 
    p1.post_author         AS  Author,
    count(p1.post_author)  AS  Posts,
    p2.post_title          AS  Title
FROM 
    wp_posts AS p1
LEFT JOIN
    wp_posts As p2
ON
    p1.ID = p2.ID
WHERE
    p1.post_type   =   'post'
AND
    p1.post_status =   'publish'
GROUP BY
    p1.post_author
ORDER BY
    Posts   DESC,
    p2.post_date   ASC
LIMIT
    2

The problem is that I always get the title of the first post and not the title of the last post. Is there a way to get the title of the last inserted post ?

Kind regards

  • 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-18T15:51:13+00:00Added an answer on June 18, 2026 at 3:51 pm

    If you only want the latest title for every author, you can use an inline correlated subquery. This will be relatively fast with proper indexes – especially if you only want results for the 2 most published authors:

    SELECT 
        post_author         AS  Author,
        COUNT(*)            AS  Posts,
        ( SELECT   p2.post_title
          FROM     wp_posts AS p2
          WHERE    p2.post_author = p1.post_author
            AND    p2.post_type = 'post'
            AND    p2.post_status = 'publish' 
          ORDER BY p2.post_date DESC
            LIMIT 1
        )                   AS  Title
    FROM 
        wp_posts AS p1
    WHERE
        post_type   =   'post'
    AND
        post_status =   'publish'
    GROUP BY
        post_author
    ORDER BY
        Posts   DESC
    LIMIT
        2 ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have something like this... $().ready(function () { $(.post .comment_this).click(function () { var comment_id
I currently have something like this: <form action=cart.php?action=update method=post name=cart id=cart> <input maxlength=3 value=25
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
I have something like this: Main view: @model AuthorViewModel @using (Html.BeginForm(Action, Controller, FormMethod.Post, new
I have something like this: function showFunction () { // need position and place
I have something like this: <?xml version=1.0 encoding=utf-8?> <Data> <ConfigDatas> <ArrayOfConfigData xmlns:i=http://www.w3.org/2001/XMLSchema-instance xmlns=http://schemas.datacontract.org/2004/07/BTTest.Models> <ConfigData>
I have something like this: [{'date': 1, 'value':5}, {'date':2,'value':3}, ...] and want to map
I have something like this : code.js var params = { option1 : encodeURIComponent(text\n
I have something like this: Map<String, String> myMap = ...; for(String key : myMap.keySet())

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.