Click to See Complete Forum and Search --> : Getting a 2nd last row from a table


arg03
06-26-2007, 08:59 AM
SELECT CONVERT(varchar(20),next_folo_date,101),insp_id
FROM Followup
WHERE folo_id = (Select Max(folo_id - 1) From Followup WHERE assess_id = 291 and folo_cnty_id = '065')


I need to get insp_id from 2nd last row and Max folo_id -1 will not work.
eg. Max folo_id for assess_id= 291,292,399 and 500 and 500-1 will be 499. witch may be entered for some other assess_id. I want to catch 399.
Any easy solution or I need to get count for the assessid 291 and catch the id for count-1.
Thanks for your help.

bubbisthedog
06-26-2007, 09:18 AM
Could you show us the table structure of Followup (e.g. in MySQL using DESCRIBE Followup)?

arg03
06-26-2007, 09:31 AM
create table Followup
(
folo_id numeric(9) not null,
assess_id numeric(9) not null,
addr_id numeric(9) not null,
folo_date datetime null ,
insp_id numeric(9) null,
next_folo_date datetime null,
folo_visit_des char(1) null ,
folo_add_date datetime null ,
folo_upd_date datetime null ,
folo_upd_user varchar(10) null ,
folo_cnty_id char(3) not null,
constraint PK_INT_ID primary key (folo_id)
)

Gaultierz
06-26-2007, 10:35 AM
Could you show us the table that contains the actual data?

arg03
06-26-2007, 11:06 AM
You no need to know actual data.

Gaultierz
06-26-2007, 11:38 PM
arg03,
I don't get your question so that I can't help you to find the answer. It would be better if you could show us a table that contain the SAMPLE data. In case you cannot show us that table, never mind!!! :)

mattyblah
06-28-2007, 12:02 AM
order by...order by...order by...how can you have a query, that needs the "second to last row" and not have an "order by" query. please adjust and you will more than likely get an answer.