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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:43:07+00:00 2026-05-20T14:43:07+00:00

I wanted to know the sql command to retrieve 5 latest row from my

  • 0

I wanted to know the sql command to retrieve 5 latest row from my table? Below is my sql query. How am I going to do, in order it can select the 5 latest row base on row no to be process?

$query = 
"SELECT lat, lng, DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS 
  datetime FROM markers1 WHERE 1";
  • 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-20T14:43:08+00:00Added an answer on May 20, 2026 at 2:43 pm

    You need to order the results, and set a limit.

    Assuming datetime is what you wanted to order on:

    $query = "
        SELECT 
            lat, 
            lng, 
            DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime 
        FROM markers1 WHERE 1
        ORDER BY datetime DESC
        LIMIT 5
    ";
    

    EDIT:
    To answer OP’s comment: “result that i get is start for Row 50 for first query and it follow by 49,48,47,46 Is that possible i can get this start frm row 46,47,48,49,50 ?”

    You could either do this with the result in PHP, by fetching the rows and storing them in an array and reversing the array. I don’t believe you can efficiently loop through a mysql result resource in reverse.

    To do this in the SQL query, you need to create a temporary table with the original query:

    $query = "
        SELECT 
            lat,
            lng,
            DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime 
        FROM (
            SELECT 
                lat, 
                lng, 
                datetime
            FROM markers1 WHERE 1
            ORDER BY datetime DESC
            LIMIT 5
        ) AS tmp_markers
        ORDER BY datetime ASC
    ";
    

    The result of the initial query is used as the table to search in a new query, that orders by datetime ascending. I had to apply the DATE_FORMAT on the outer query because we need the datetime field to order by again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to know if we can timeout a sql query. In the sense,
I want to create a veiw and then select from it in one query,
Having multiple indices for an SQL table, is there a way to know what
I wanted to know if it was possible can do a db dump of
I wanted to know if in SQL Server there is an equivalent to the
I need to install SQL Server 2008 on the server. I wanted to know
I wanted to know how to detect which edition of SQL Server 2008 is
I wanted to know, while deciding which language or technology to use for implementing
I wanted to know what the public opinion is about Resharper vs Devxpress CodeRush
I wanted to know why UDP is used in RTP rather than TCP ?.

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.