Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Postgresql Querying the last 10 records from the database

Posted on 2004-10-24
5
Medium Priority
?
287 Views
Last Modified: 2008-03-06
Hi Sir,
Can you help me in writing a query for retrieving Postgresql Querying the last 10 records (recent) from the database. Its urgent
0
Comment
Question by:ekartha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 1000 total points
ID: 12398511
If you just want to retrieve the last 10 records which were inserted (not considering update),      with your auto_increment column, you can use:
SELECT * FROM yourtablename ORDER BY your_auto_increment_column LIMIT 10;
      
PS: ORDER BY your_auto_increment_column is optional. This should be enough:
SELECT * FROM yourtablename LIMIT 10;
      
However, if the records are updatable and you want to retrieve the last 10 records which were accessed (either updated or inserted records), you need a date column like 'last_modified' which stores the date & time at which a record was inserted or updated.
      
Then you can use:
SELECT * FROM yourtablename ORDER BY last_modified_column LIMIT 10;
0
 
LVL 9

Assisted Solution

by:rjkimble
rjkimble earned 1000 total points
ID: 12403591
I think you need to add "DESCENDING" to those ORDER BY clauses to achieve what you want.
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12408460
yes, good point. So, the query should be like:
SELECT * FROM yourtablename ORDER BY corresponding_col DESC LIMIT 10;
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question