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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:51:09+00:00 2026-05-28T01:51:09+00:00

I want to select the newest posts from users, I am looking for the

  • 0

I want to select the newest posts from users, I am looking for the most efficient way to do this.

Currently this selects the first post, not the last:

$query = mysql_query("
                     SELECT * 
                     FROM posts 
                     WHERE toID=fromID 
                     GROUP BY fromID 
                     ORDER BY date DESC LIMIT 3");

Table Structure:

Table: posts

id  ToID    FromID  Post        State   Date
1   1       1       Hey         0       1325993600
2   1       6       okay yeah   0       1325993615
3   1       2       again       0       1325994600
4   6       6       yeah2       0       1325995615

so from this above example it would return id: 1 and 4.

toID=fromID is just to get the post that is a status message, meaning the user posted something on their own page, not someone elses.

I want to get the most recent status from the last 3 users that have updated their status.

  • 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-28T01:51:09+00:00Added an answer on May 28, 2026 at 1:51 am

    The ID thing would still work theoretically, provided that the ID’s never change…

    I would recommend using a timestamp field in the table structure called “date” and use the “CURRENT_TIMESTAMP” as default value, this will auto-populate the date/time on the record upon insert…

    Order by this field DESC, limit x

    Also, I have experienced many cases of the wrong data appearing thanks to grouping… Make sure your data is correct before ORDER BY and LIMIT is applied

    For getting posts from user1 to user1 there’s no need to group by:

    SELECT * FROM posts 
    WHERE toID=fromID
    ORDER BY date DESC LIMIT 3
    

    For getting posts from * to user1:

    SELECT * FROM posts 
    WHERE toID="USER1_ID"
    ORDER BY date DESC LIMIT 3
    

    For getting posts from * to user1, only unique users:

    SELECT * FROM posts 
    WHERE toID="USER1_ID"
    GROUP BY FromID
    ORDER BY date DESC LIMIT 3
    

    Somtimes you will run into the problem where GROUPED records are not ordered by ORDER BY, because the ORDER BY is applied to the result AFTER the grouping is applied… To achieve a workaround:

    SELECT * FROM (
      SELECT * FROM posts 
      WHERE toID="USER1_ID"
      ORDER BY date DESC
    ) as `derived` GROUP BY FromID LIMIT 3
    

    To Get the last 3 users who have most recently sent themselves a post:

    SELECT * FROM (
      SELECT * FROM posts 
      WHERE toID=fromID
      ORDER BY date DESC
    ) as `derived` GROUP BY FromID LIMIT 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have users table and i have posts table i want select from users
I just want to select the newest 3 comments on a post, and have
i want something like this: SELECT DISTINCT ID from copies WHERE timestamp < 1229444506
I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
I want to SELECT a formatted date string from a datetime type in SQL
This query SELECT PA.refPatient_id ,MAX(PA.datee) AS datee ,PR.temporary,PA.statue FROM PatientClinicActs AS PA ,PatientStatueReasons AS
How can i select the newest 5 rows from mysql (newest by id for
I am trying to select the most recent record between 2 users based on
So I just wrote this little script. The problem is I want the newest
I want select multiple (all) values from table Account. string query = SELECT *

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.