By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,514 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,514 IT Pros & Developers. It's quick & easy.

SQL question!!

P: 1
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
Share this Question
Share on Google+
1 Reply


nearestniladri
P: 5
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.