Solved

select the first 5 rows in DB2

Posted on 2001-07-02
4
808 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

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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