DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: SQL: How do I get just the first row of a result set?

  1. #1
    Join Date
    Feb 2005
    Posts
    4

    SQL: How do I get just the first row of a result set?

    I need to get the first row returned from a select query that looks like this:

    SELECT DISTINCT parm1 FROM table1 WHERE parm1 > 10 ORDER BY parm1

    Can someone please show me how to do this?

    Alex

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Quote Originally Posted by bort
    I need to get the first row returned from a select query that looks like this:

    SELECT DISTINCT parm1 FROM table1 WHERE parm1 > 10 ORDER BY parm1

    Can someone please show me how to do this?

    Alex

    Code:
    select * from (
       SELECT DISTINCT parm1 FROM table1 WHERE parm1 > 10 ORDER BY parm1 )
    where rownum < 2
    Jeff Hunter

  3. #3
    Join Date
    Feb 2005
    Posts
    158
    SELECT min(parm1) FROM table1 WHERE parm1 > 10
    would achieve (almost) the same result in this case.
    Almost being, this would return null if there were no records, rather than a no rows returned/no_data_found

  4. #4
    Join Date
    Feb 2005
    Posts
    4
    Quote Originally Posted by gamyers
    SELECT min(parm1) FROM table1 WHERE parm1 > 10
    would achieve (almost) the same result in this case.
    Almost being, this would return null if there were no records, rather than a no rows returned/no_data_found
    That's exactly what I ended up doing. Thanks for the replies!

Posting Permissions

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


Click Here to Expand Forum to Full Width