Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyOne,



I have One Table 'tbl_student' fields are (Name,Class,Age,Address) OK.

No id column(primary key and identity ok)in my table.
I entered records,

Name Class Age Address
------ ------ ----- --------
Mohan X 18 Erode
Kumar XII 20 Chennai ---->1
Arun XI 19 Trichy
Bala VII 17 Coimbatore ---->2
Vijay VIII 17 Chennai
Karthi X 19 Erode


I stored 'Kumar' and 'Bala' Details(1,2) finally ok.
then...

How I get these Last 2 TRANSACTIONS from sql query
any One Known plz tell me....

By from Mohan.
Posted

Last 2 TRANSACTIONS from sql query
Sounds like you are looking at time based records. In order to have it, add one more column to the table 'LastUpdated'. Populate it at the time of insertion/updation. Once you have this data in the table, you can get the first, last or time range based data whenever needed.
 
Share this answer
 
Comments
Mohankumar.Engain 10-May-11 1:55am    
thanks
You can't retrieve data based on the transactions. You could retrieve the row_number(), but this would only tell you the records inserted, which is not necessarily the last transactions because one transaction might be an update. With that constraint in mind, the way to do this would be to use something like
SQL
select top 2 row_number() over (order by Name desc) as 'RowNum', ...
from tbl_student
group by Name
order by Name desc
Note that I haven't tested this, it's just been entered in the editor so you may have to tweak the syntax a little bit.
 
Share this answer
 
Comments
Mohankumar.Engain 10-May-11 1:55am    
Thanks....
Mohankumar.Engain 10-May-11 2:54am    
But this query execute Order wise not recent transactions wise...
Pete O'Hanlon 10-May-11 3:18am    
This is why I put the caveat in that it would only cover inserts. The alternative is to have a last updated column which you would order over.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900