242

How to get the last 3 records

 3 years ago
source link: https://www.codesd.com/item/how-to-get-the-last-3-records.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to get the last 3 records

advertisements

I am adding new record for every transaction

For Example: microfinance,

  1. Today customer paid 300, then new record is inserted
  2. tomorrow 500 again new record is inserted)

then how can i get last 3 records based on customer id.

table

ID               Password            Amount
1                  a                   200
2                  s                   500
1                  a                   100
3                  b                   200
1                  a                   300
1                  a                   300

there is no primary key

i want last inserted 3 records for id=1


I believe you need something like this:

SELECT *
FROM Table
ORDER BY id DESC
LIMIT 0,3

Related Articles

How to get the last 10 records from the table in the codeignor

i have controller that have function to get my post from table like this:- function getPosts($user_id, $from, $to) { $this->db->order_by("ev_date", "DESC"); $query = $this->db->get_where($this->table_name, array('ev_user

How to get the last 50 records created in ascending order in Ruby On Rails

I got a table that saves executed purchase orders. For a report I want to have the last 50 created purchase orders (the table's ID field is good to identify those) listed in ascending order. I tried a = Order.limit(50).order("id desc").order(&qu

How to get the last updated record in SQL?

I have written query but I'm not getting latest updated data. I mean I have psn update column , I want current positiondata of latest updated date , according to "latestpsnupdate" I need currentposition. SELECT k.KeyWord, pa.UserName, pa.ProjId,

How to get the latest N records inserted from mongodb using Java?

There is an analogous post for using mongodb scripting mongodb: how to get the last N records? How to achieve the same goal with Java getting the last inserted collection document? Just in case, I am using the 3rd version of the mongodb Java driver,

How to get the last record in MySql with 2.5 m lines

I want to get the last record in my MySql table, but the table has 2.5 million rows. How to get the last row efficiently? I'm using order and limit but the query runs ~15sec. I have to decrease this value to nearly zero. My SQL Query : SELECT id FROM

Mongodb: How to get the latest N records?

I can't find anywhere it has been documented this. By default, the find() operation will get the records from beginning. How can I get the last N records in mongodb? Edit: also I want the returned result ordered from less recent to most recent, not t

How to get the latest x records from a list with Lambda

I have as List of strings with where i remove each duplicates, now I want to filter it even more to get the last 5 records. How can I do this? What I got so far List<string> query = otherlist.Distinct().Select(a => a).ToList(); You do not need th

How to get the last indexed index to Solr?

I want to know how to get/search last indexed record in Apache Solr..? When the existing record is updated then it goes to end of all the records...so I want to get that last indexed record. thanks..You could add a 'timestamp' field to your Solr sche

Spring Data JPA Java - Get the last 10 records of the query

Is there a way to retrieve the last X number of results from a query? For example - If want the first ten results, I see that example here works: setMaxResults for Spring-Data-JPA annotation? public interface UserRepository extends Repository<User, L

Monk: How to get the latest N records?

I can't find where this is documented. By default, the find() operation will get the records from beginning. router.get('/chat/get-messages', function(req, res) { var db = req.db; var collection = db.get('chatMessages'); collection.find({},{'limit':8

How to get the last character of a string?

How to get the last character of the string: "linto.yahoo.com." The last character of this string is "." How can I find this?An elegant and short alternative, is the String.prototype.slice method. Just by: str.slice(-1); A negative sta

SQL gets the last time record of the date

I'm trying to get the last datetime record from a table that happens to store multiple status. My table looks like so: +---------+------------------------+-------+ |filename |Dates |Status | +---------+------------------------+-------+ |abc.txt |2012

How to get the last part of $ (MSBuildProjectDirectory)

Can't figure out how to get the last part of $(MSBuildProjectDirectory) For example, if the value was "c:\development\projects\project_branch" then, I want just the last part "project_branch". Any ideas? Thanks, SeanIn 4.0+ you can use

how to get the last value of the array in swap in loops

Here is my code: class test { public static void main(String args[]) { int a[]={5,8,9,7,3}; int j; for(j=0;j<a.length-1;j++) { if(a[j]>a[j+1]) { int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } System.out.print(a[j]+" "); // last value of array

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK