Solved

select the first 5 rows in DB2

Posted on 2001-07-02
4
806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

732 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