quary for
1> fetch last record
2> fetch in reverse order
3> fetch last 5 row
4> fetch second last record (their is no primary key)
i think concept of count can be use for this in 4th

Answers were Sorted based on User's Feedback



quary for 1> fetch last record 2> fetch in reverse order 3> fetch last 5 row 4> fet..

Answer / sarath

1) select id,name from tab1 order by id desc fetch first
row only
2) select id,name from tab1 order by id desc
3) select id,name from tab1 order by id desc fetch first 5
rows only
4) select id,count(*),name from tab1 order by id where count
(*) = (select count(*) from tab1)-1

Is This Answer Correct ?    6 Yes 3 No

quary for 1> fetch last record 2> fetch in reverse order 3> fetch last 5 row 4> fet..

Answer / pavan

please try this one and let me know....


select * from emp where :ws-rec-cnt = (select Count(*)
into :ws-rec-cnt from emp);

Is This Answer Correct ?    3 Yes 2 No

quary for 1> fetch last record 2> fetch in reverse order 3> fetch last 5 row 4> fet..

Answer / pavan

the above one is for fetching last record and i think u can
decraese (use < symbol) the count and use it for fetching
nth record in a table.

Is This Answer Correct ?    2 Yes 1 No

quary for 1> fetch last record 2> fetch in reverse order 3> fetch last 5 row 4> fet..

Answer / sudipta

the 4th answer is(ignore the previous one)

db2=> with t1(a,b,c) as (select id,name,row_number()
over(order by id desc) as aa from tab1) select * from t1
where c=2

Is This Answer Correct ?    2 Yes 1 No

quary for 1> fetch last record 2> fetch in reverse order 3> fetch last 5 row 4> fet..

Answer / sudipta

u may try this
assuming table 'tab1' has 2 fields id & name
1) select id,name from tab1 order by id desc fetch first
row only
2) select id,name from tab1 order by id desc
3) select id,name from tab1 order by id desc fetch first 5
rows only
4) select id,count(*),name from tab1 order by id where count
(*)<(select count(*) from tab1)

u try these & if any problem u may write

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More DB2 Interview Questions

What will the FREE command do to a plan?

2 Answers  


How we create a tables in DB2 ?Previously client has using 7 letters for user id,now he wants to increase the letters from 7 to 12 for user id.How we can do it?

6 Answers   Wipro,


How to find the maximum value in a column in the db2 database?

0 Answers  


Can we use select * statement in cobol program without giving field names ???

3 Answers   Zensar,


What if we try to insert the base table through updatable view , but failed to give a column value which is defined as NOT NULL.

1 Answers   Cap Gemini,






how to check the table is empty or not?

3 Answers   IBM,


What is EXPLAIN?

1 Answers  


What is the difference between Where and Having Clause

7 Answers   IBM, iFlex,


What are iseries servers?

0 Answers  


Normalization in DB2 – first normal form, second normal form

4 Answers   Virtusa,


how will i display the duplicate record's from a table... i don't want to eliminate ...i want to display the duplicate record...for example in my table i have 10 record's like record no(1,2,3,4,2,9,6,1) in this ...so i want to receive duplicates...

1 Answers   UST,


What is the difference between db2 and oracle?

0 Answers  


Categories