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

Thread: Subquery question

  1. #1
    Join Date
    Nov 2000
    Posts
    416
    Can somebody with an example tell me how many values could a subquery with a single row comparison operator return and why ?

    An ounce of prevention is worth a pound of cure

  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    ?

  3. #3
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    7
    Jeff Hunter

  4. #4
    Join Date
    May 2001
    Posts
    70
    farrokhp-

    Are you talking about the exists / not exists subqueries in your where clause?

    If it that I believe that answer would be one because in the past when I wasn't unique to one row I had lots of errors generated.

    Good Luck

  5. #5
    Join Date
    Nov 2000
    Posts
    416
    In fact this is an OCP question and I think the correct answer is ' 1 ' but I don't know why :( Now can you help more
    An ounce of prevention is worth a pound of cure

  6. #6
    Join Date
    May 2001
    Posts
    70
    I think it is due to the fact your not returning one row or unique row.

    I am not an OCP person, and I have found the questions to be interesting.

    Another one you will need to know is how the PL/SQL engine processes different PL/SQL blocks of code.

    Good Luck

  7. #7
    Join Date
    Jul 2000
    Posts
    296
    The subquery can return any number of rows, 0, 1, 10 or 8634785, it depends on the subquery. If it returns more than 1 row you get an error.

    Try these queries:

    SELECT *
    FROM emp
    WHERE deptno = (SELECT deptno FROM dept WHERE deptno = 0);

    SELECT *
    FROM emp
    WHERE deptno = (SELECT deptno FROM dept WHERE deptno = 10);

    SELECT *
    FROM emp
    WHERE deptno = (SELECT deptno FROM dept);

  8. #8
    Join Date
    May 2001
    Posts
    70
    Akkerend,

    I believe your last example is wrong. I think you meant use an "in" instead of "=".

    Which then allows more than one row to be returned in the subquery.

  9. #9
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    That is his point, actually. The aswer to the question, as stated, is *any non-negative number*. As akerand has shown, a SQL statement with a sub-query and 'single row comparison operator' (=) can return *any* number of rows. however, if that number is greater than 1, then an error is generated. If the question had included the phrase 'without error', or something similar, then the answer would have been 1 or 0. See, the question is still not specific enough to only have a single numeric answer.

    - Chris

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