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
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 |
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 |
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 |
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 |
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 |
How would you find out the total number of rows in a db2 table?
What is a db2 table?
Explain about rct.
i want to know how the commit option works,how it save the changes? it will update the database or what ? where we can see these saved changes?
What is the cobol picture clause of the db2 data types date, time, timestamp?
What is a DBRM, PLAN ?
I have a table name Table1 which contain columns Cust_no, car_model, country, salesamt. The records are 101, Fiat, India, 12345 2nd record is 102, Tata, USA, 98743 3rd record is 101, indica, India, 65342 4th record is 103, Toyota, UK, 64522 5th record is 103, Maruti, USA, 98632 and so on..... Now my question is write sql query which will give me detail about the sum of sales amount in perticular country
which is the most efficient tablespace?? a.simple tablespace. b.partitioned tablespace. c.segmented tablespace. d.none of the above. please post answer with the reason.?
What does the CHECK Utility do ?
I am getting a error multiple row fetched while executing a Cobol-DB2 program.How can I solve it without using a cursor.
Is db2 relational database?
My sql statement select avg(salary) from emp yields inaccurate results. Why?