Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    61

    Unanswered: Select top or first n row

    Hi All,

    Please let me know how I can select top 10 row.
    Some way like in SQL server:
    select top 10 * from sysobjects;

    Thanks in advance
    Thi Nguyen

  2. #2
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    524
    using set rowcount 10. Then don't forget to remove it using set rowcount 0.
    F. Celaia
    DBA Sybase/DB2/Oracle/MS-SQL

  3. #3
    Join Date
    Jul 2004
    Posts
    61
    Hi Fadace

    Thanks a lot for your help.

    In fact, I want select top 5 rows from table A and the union select top 5 row from table B.
    Some things like :

    select top 5 * from A
    union
    select top 5 * from B

    Thanks
    Thi Nguyen

  4. #4
    Join Date
    Jun 2004
    Location
    Paris, France
    Posts
    43
    then you'll have to use temp table...
    otherwise you will only get the 5 first of table A...

    but if you have some rows present in the two result sets, you will have less than 10 rows after the union of the 2 temp tables...

    so you can try this...

    set rowcount 10

    select * from A into #A
    select * from B into #B

    set rowcount 5
    select * from #A into #C

    insert into #C
    select * from #B
    where [not in #C]... if you can have a key for this...

    set rowcount 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •