?
Solved

select the first 5 rows in DB2

Posted on 2001-07-02
4
Medium Priority
?
813 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 20 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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