Solved

select the first 5 rows in DB2

Posted on 2001-07-02
4
799 Views
Last Modified: 2006-11-17
Hi all :->

From what i know different database will support different sets of sql syntax like for select the first 5 rows -

in sqlserver and ms access
"select top 5 from..."

in oracle
" select... where rownum <= 5"

but in db2 ???
can anyone pls tell me...
thanks
0
Comment
Question by:aili
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
nigelrivett earned 5 total points
ID: 6244575
select *
from   ...
fetch first 5 rows only
0
 

Author Comment

by:aili
ID: 6247023
Ghee thanks a lit nigelrivett,

thanks for your help...
By the way, do you know any more differences in sql statement between oracle and db2...

:-)


0
 

Author Comment

by:aili
ID: 6247152
Oops.. i have another problem here if it is just a normal sql statement it will work but however when i create this with a view it give me error...

"create view test as select * from tablename fetch first 5 rows only"

and the error saying :

DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "from tablename" was found following "iew test as
select *".  Expected tokens may include:  "<space>".  SQLSTATE=42601

so wat is the problem now? :-(


0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6249610
I suspect you can't do this in a view.
you need the select in the view and the fetch in the sql statement.

In sql server I never use views as they are not necessary as you have SPs. I believe they are in Oracle - don't know about DB2.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question