Blogroll

Get a website with Godaddy


Logo designer Fiverr Frelancer

Monday, March 19, 2018

SQL - How to retrieve last 100 records ?

Hi, there.
Normally when we do data validation, we need to retrieve some latest records. Let's take last 100 records.

Method 1 by datetime field 

USE [dataDB]

go

select top 100 * from tbltransaction
order by trdate desc, trtime desc

Method 2 by running no ID field (PK)

USE [dataDB]
go

select * from tblTransaction
where ID >
( (select COUNT(*) from tblTransaction) - 150)
order by ID desc

No comments:

Post a Comment

Amazon store

alidropship plugin

alidropship plugin
alidropship plugin

Total Pageviews

About