Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL Query Help

Re: SQL Query Help

From: Matthias Gresz <GreMa_at_t-online.de>
Date: 1997/11/25
Message-ID: <65dsqg$dq7$2@news02.btx.dtag.de>#1/1

Wallace Fukumae wrote:
>
> Problem:
> A tableT has two fields 'fieldA', 'fieldB'. fieldA is a character field
> but contains
> only numbers for priorities. fieldB is a character field identifying the
> record.
> I would like to generate a query which would return rownum,fieldA,fieldB
> from
> tableT but ordered by fieldA. For example, I would like to return the top
> 500 records from tableT. However, as we know if you use the order by
> clause with rownum, rownum is based only off of the select, so rownum
> would be correct for the select but as soon as the sorting takes place
> with the order by clause rownum would be out of sync.
>
> TABLE T:
> fieldA number
> fieldB varchar2(10)
>
> SAMPLE DATA:
> HONDA 44
> TOYOTA 45
> HYUNDAI 90
> FORD 5
> CHEVORLET 8
>
> DESIRE:
> 1 FORD 5
> 2 CHEVORLET 8
> 3 HONDA 44
> 4 TOYOTA 45
> 5 HYUNDAI 90
>
> Thanks, Wally

Hi Wally,

just try something like this:

select
rownum, ename, empno
from
emp
where rownum <7
order by
empno desc;

or

Select rownum, a.ename, a.empno
from
(
select
ename, empno
from
emp
group by empno, ename
) a
where
rownum < 7 ;

-- 
Regards

Matthias Gresz    :-)
Received on Tue Nov 25 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US