Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    69

    Unanswered: Order by -- To get the second Row -SQL

    Hi,
    My sql query is like the bellow,


    """
    Select app_no,month,year from mytable where app_no=2 order by
    month desc
    """


    This query will give me the bellow details,

    app no month year
    -------- ------- -----
    2 9 2000
    2 8 2000 -->
    2 8 2000
    2 7 2000


    Now I need to select the second record ( which I marked with -->) from the query itself. How can I do it?
    Thanks,
    Anto.A.R.

  2. #2
    Join Date
    Jan 2002
    Location
    USA
    Posts
    53
    Maybe you can use

    with tmp (app_no,month,year) as (Select app_no,month,year from mytable where app_no=2 order by month desc ) select * from tmp where ...


    WTH


    -ljrong

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Order by -- To get the second Row -SQL

    Originally posted by antodomnic
    Hi,
    My sql query is like the bellow,


    """
    Select app_no,month,year from mytable where app_no=2 order by
    month desc
    """


    This query will give me the bellow details,

    app no month year
    -------- ------- -----
    2 9 2000
    2 8 2000 -->
    2 8 2000
    2 7 2000


    Now I need to select the second record ( which I marked with -->) from the query itself. How can I do it?
    Thanks,
    Anto.A.R.
    May be this would work:

    with t as (select app_no,month,year, rownumber() over (order by month desc) as rnum from mytable where app_no=2) select * from t where rnum=2
    ---
    "It does not work" is not a valid problem statement.

  4. #4
    Join Date
    Mar 2003
    Posts
    69
    But, Sorry that it is not working . My environment is db2 v6.1 running on OS/390.

Posting Permissions

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