469,270 Members | 1,818 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

SQL question!!

Hi -

I want to get the db2 SQL output of a query, WHERE B>=90 and wherever it find the matching condition it should fetch preceding 3 rows.

For Example -
A B
- -
1 5
0 6
5 8
1 10
2 20
3 30
4 98
5 50
11 55
6 60
7 70
8 90
9100

So the output should be based on above criteria -
A B
- -
1 10
2 20
3 30
4 98
11 55
6 60
7 70
8 90

Any help will be appreciated.

Thanks
Sandip
Nov 20 '07 #1
1 1049
If you want to get the first 3 rows, then your SQL statement need to be like:

select * from table_name where B<=90 fetch first 3 rows only.


Actually the statement is for fetching first n rows is:

select * from table_name fetch first n rows only.
Nov 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Stevey | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.