Query the first 2 records from a table. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Query the first 2 records from a table.

azzchongazzchong Posts: 4Member
[b][red]This message was edited by azzchong at 2003-5-4 6:59:36[/red][/b][hr]
I need to query the first 2 records from a table in any kinds of sorting and any condition. (With Oracle Database)

Thanks for help.


Comments

  • raymcdraymcd Posts: 284Member
    : [b][red]This message was edited by azzchong at 2003-5-4 6:59:36[/red][/b][hr]
    : I need to query the first 2 records from a table in any kinds of sorting and any condition. (With Oracle Database)
    :
    : Thanks for help.
    :
    :
    :

    Select * from TableNameHERE Where rownum < 3;

    (or rownum < 2 I can't remember if it is zero based)

    -Ray

  • infidelinfidel Posts: 2,900Member
    : : [b][red]This message was edited by azzchong at 2003-5-4 6:59:36[/red][/b][hr]
    : : I need to query the first 2 records from a table in any kinds of sorting and any condition. (With Oracle Database)
    : :
    : : Thanks for help.
    : :
    : :
    : :
    :
    : Select * from TableNameHERE Where rownum < 3;
    :
    : (or rownum < 2 I can't remember if it is zero based)
    :
    : -Ray

    It's 1 based, so you want < 3. If you want the records sorted first, then you have to do it like this:

    [code]
    select *
    from (select * from tablename
    where some condition
    order by something)
    where rownum < 3;
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.