Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.