Solved

select the first 5 rows in DB2

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now