Results 1 to 5 of 5

Thread: Select top DB2

  1. #1
    Join Date
    Mar 2006
    Posts
    3

    Unanswered: Select top DB2

    Hello!

    Somebody could help me with this query?

    select top 10 * from table1 where code not in (select top 5 code from table1)

    I tried it but DB2 do not support top. I used fetch first row only

    My problem is that in the first query the fetch first row only work well but in the second subquery do not work well.

    thank you in advance

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    What version of db2 are you using ???? Please always include this information.

    On DB2 LUW V8 FP10, this works

    select * from syscat.tables where tbspace not in (select tbspace from syscat.tablespaces fetch first 10 rows only) fetch first 10 rows only with ur
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Mar 2006
    Posts
    3
    Quote Originally Posted by sathyaram_s
    What version of db2 are you using ???? Please always include this information.

    On DB2 LUW V8 FP10, this works

    select * from syscat.tables where tbspace not in (select tbspace from syscat.tablespaces fetch first 10 rows only) fetch first 10 rows only with ur

    Sorry!

    I am trying to excute this query using ODBC client access that connect to IBM AS400 with DB2 V5R3

    thanks

  4. #4
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,
    using 'fetch' in subselect is new functionality of DB2 v8.1
    Grofaty

  5. #5
    Join Date
    Sep 2012
    Posts
    1
    Here is the DB2 script to display first 50 rows : select * from DBO.Table1 fetch first 50 rows only
    For SQL Server t-sql script it is select Top 50 * from DBO.Table1

Posting Permissions

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