[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Syntax

Posted on 2011-10-28
5
Medium Priority
?
285 Views
Last Modified: 2012-05-12
Hi,

I have this query tat outputs a result of more than 3million rows.. How can I set it to ouput only N number of rows?
Like the first 1000 or something like this...

select
dpsc.dsc_icid
from
dp_cad dpsc,
dp_cadprofle dpcp,
JM_Paage jampkg,
JM_CgeInstance jamcpi
where
dpsc.dpsc_id=jamcpi.dpsc_id and
jamcpi.jampkg_id=jampkg.jampkg_id and
jampkg.jampkg_id=6779 and
dpsc.dpcp_id=dpcp.dpcp_id and
dpcp_name='T7.0'
;

Tks,
Joao
0
Comment
Question by:joaotelles
  • 2
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 1000 total points
ID: 37044403
select
dpsc.dsc_icid
from
dp_cad dpsc,
dp_cadprofle dpcp,
JM_Paage jampkg,
JM_CgeInstance jamcpi
where
dpsc.dpsc_id=jamcpi.dpsc_id and
jamcpi.jampkg_id=jampkg.jampkg_id and
jampkg.jampkg_id=6779 and
dpsc.dpcp_id=dpcp.dpcp_id and
dpcp_name='T7.0'
and rownum <= 1000
;
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 37044406
- try this:

select
dpsc.dsc_icid
from
dp_cad dpsc,
dp_cadprofle dpcp,
JM_Paage jampkg,
JM_CgeInstance jamcpi
where
dpsc.dpsc_id=jamcpi.dpsc_id and
jamcpi.jampkg_id=jampkg.jampkg_id and
jampkg.jampkg_id=6779 and
dpsc.dpcp_id=dpcp.dpcp_id and
dpcp_name='T7.0'
WHERE ROWNUM < 1001;
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 37044407
better would be to apply an ORDER BY clause so you can determine which rows will be first

select dsc_icid from (
select
dpsc.dsc_icid
from
dp_cad dpsc,
dp_cadprofle dpcp,
JM_Paage jampkg,
JM_CgeInstance jamcpi
where
dpsc.dpsc_id=jamcpi.dpsc_id and
jamcpi.jampkg_id=jampkg.jampkg_id and
jampkg.jampkg_id=6779 and
dpsc.dpcp_id=dpcp.dpcp_id and
dpcp_name='T7.0'
order by dpsc.dsc_icid
)
where rownum <= 1000
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 37044410
- opsss.. wrong and late. ignore mine :)
0
 

Author Closing Comment

by:joaotelles
ID: 37044411
tks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

829 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