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

Thread: select in the select

  1. #1
    Join Date
    Dec 2003
    Posts
    90

    select in the select

    its friday, thats all i have to say!!

    how would you do this

    select b.id, rownum rn, (select count(id) FROM b) id_cnt
    from (SELECT * FROM caw_dataobjects WHERE id < 1000) b;

    This is obviously wrong, so is it possible to do the 'from' on the first line by referencing that table labelled as 'b' on the second line?
    I'm trying to do it without repeating the query like this

    select b.id, rownum rn, (select count(id) FROM (SELECT * FROM caw_dataobjects WHERE id < 1000)) id_cnt
    from (SELECT * FROM caw_dataobjects WHERE id < 1000) b;

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    The most efficient way would be to use an analytic function, something like ...
    Code:
    select
       col1,
       col2,
       ...
       total_rows
    From
       (
       select
          col1,
          col2,
          ...
          Count(*) Over () total_rows
       from
          caw_dataobjects
       where id < 1000
       )
    /
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Dec 2003
    Posts
    90
    That'll do nicely, thanks.

    I never knew about the analytic functions.

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