What statement could I use to retrieve the last 8 rows in a table? It would be easier if I could select the last row and then the last row -1 etc. any ideas???
Michael Fitzmaurice
Ranch Hand
Joined: Aug 22, 2001
Posts: 168
posted
0
Hi Use a loop where you get the last row (as explained in response to your query about that), then (in a loop) subtract 1 from the value of the artID you used to get that row and get the matching row for that artID. Repeat 6 more times. To do it this way, you must be sure that the artID fields are all sequential and ordered, i.e. there is no possibility that one of them has been deleted (e.g. artID 10, 9, and 7 exist, but 8 has been deleted - problems ensue). It would probably be best to write a small stored procedure to return you a resultset containing the last 8 rows only. But you could do it all by executing 8 Statement.execute() calls, if you really want. ------------------ "One good thing about music - when it hits, you feel no pain" Bob Marley [This message has been edited by Michael Fitzmaurice (edited September 12, 2001).]
"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Suji N
Ranch Hand
Joined: Sep 04, 2001
Posts: 35
posted
0
check the following code....which was done on using a w t it will be verymuch useful if u got any pblm...tell me i will solve it import java.awt.*; import java.awt.event.*; import java.sql.*; public class UserSearch extends Panel implements ActionListener, TextListener { Label totalrecords, userIDLbl,userNameLbl,title, label1, label2, label3, label4, label5; TextField userIDTxt,userNameTxt; Button previous,search,nextPage,reset,exit; TextField tf[][]; int i,recPos,recCount; boolean nextP,prev,ent;
setLocation(295,115); // width and height setSize(570,508);// size of the window setVisible(true); setLayout(null); userNameLbl.setText("UserName"); add(userNameLbl); userNameLbl.setBounds(264,60,66,28);
1. if using oracle: "select x,y from table order by rownum desc" then you can iterate through the first 8 rows(which are actually the last 8 rows) 2. if you have a timestamp field in your table: "select x,y from table order by timestampfield desc" then you can iterate through the first 8 rows 3. if have no other alternative(you will have to select all the records and only use the last 8!)
for 1 and 2 you can statement.setMaxRows(8); Jamie
[This message has been edited by Jamie Robertson (edited September 13, 2001).]
4. If you have a primary key that is autonumber or some type of incrementing number then you could: "select x,y from table order by id desc" then you can iterate through the first 8 rows and again setMaxRows(8). Jamie
Pranit Saha
Ranch Hand
Joined: Sep 09, 2001
Posts: 130
posted
0
Hi jamie.. Thanks for ur sugession.. it has helped me a lot to solve my problem.. Pranit..
Originally posted by Jamie Robertson: 4. If you have a primary key that is autonumber or some type of incrementing number then you could: "select x,y from table order by id desc" then you can iterate through the first 8 rows and again setMaxRows(8). Jamie