Correlated subqueries in SQLJ

HI,
I found I couldn't do correlated subqueries using SQLJ. example:
#sql {
select A.login_id, B.code, B.created, B.status from table1 A, table2 B where A.user_id=B.user_id(+) and (B.status='A' or B.user_id is null or B.created=(select max(created) from table2 where B.user_id=user_id) ) order by B.status
SQLJ compiler complian "Error: Unable to check SQL statement. Error returned by database is: ORA-00904: invalid column name".
Did any of you ever did correlated subqueries in SQLJ?
Thanks a lot.

Would you please confirm that CQL does NOT support correlated sub-queries?

Similar Messages

  • Correlated Subqueries, NOT EXISTS & Anti Joins - Clarification

    I am a bit confused now regarding correlated subqueries and the NOT EXISTS operator (I had originally thought I understood but am all mixed up now!)
    I was reading around and have gathered that if one were to use EXISTS that this isnt the preferred method, and that the query should actually be re-written as a join (im guessing INNER JOIN) to improve performance.
    NOT EXISTS is also not a recommended method from what I read as well.
    Correlated subqueries in general are not recommended for performance issues, since the subquery needs to be executed once for every row returned by the outer query.
    I was reading up on anti joins, and found that a lot of people referred to anti joins with the use of NOT EXISTS and a correlated subquery, which if my above understanding is correct is super bad in performance as it combines two things that people dont recommend.
    I was wondering for anti joins, is there any other way to write them besides a NOT EXISTS with a correlated subquery?
    Essentially what would be the most efficient way of writing an anti join? Or when Im trying to find all the rows that are NOT a common match between two tables.

    Hi,
    chillychin wrote:
    I am a bit confused now regarding correlated subqueries and the NOT EXISTS operator (I had originally thought I understood but am all mixed up now!)That's easy to understand! This is a topic that does not lend itself to easy, general solutions. So much depends on the circumstances of a particular query that you can never honestly say anything like "EXISTS is bad".
    I was reading around and have gathered that if one were to use EXISTS that this isnt the preferred method, and that the query should actually be re-written as a join (im guessing INNER JOIN) to improve performance. It depends. EXISTS and joins do different things. For example, when you have a one-to-many relationship, joining can increase the number of rows. Even if the join is faster than EXISTS, you may have the additional cost of doing a GROUP BY or SELECT DISTINCT to get just one copy of each row.
    NOT EXISTS is also not a recommended method from what I read as well.
    Correlated subqueries in general are not recommended for performance issues, since the subquery needs to be executed once for every row returned by the outer query.There's a lot of truth in that. However, results of coirrelated queries can be cached. That is, the system may remeber the value of a correlation variable and the value it retuned, so the next time you need to run the sub-query for the same value, it will just return the cached result, and not actually run the query again.
    Remember that performance is only one consideration. Sometimes performance is extremely important, but sometimes it is not important at all. Whether a query is easy to understand and maintain is another consideration, that is sometimes more important than performace.
    The optimizer may re-write your code in any case. When perforance really is an issue, there's no substitute for doing a EXPLAIN PLAN, finding out what's making the query slow, and addressing those issues.
    I was reading up on anti joins, and found that a lot of people referred to anti joins with the use of NOT EXISTS and a correlated subquery, which if my above understanding is correct is super bad in performance as it combines two things that people dont recommend. It's actually only one thing that the people who don't recommend it don't recommend. EXISTS sub-queries are always correlated. (Well, almost always. In over 20 years of writing Oracle queries, I only remember seeing one uncorrelated EXISTS sub-query that wasn't a mistake, and that was in a forum question that might have been hypothetical.) Nobody worth listening to objects to EXISTS because it is EXISTS, or to a correlated sub-query because it is correlated. They object to things because they are slow (or confusing, or fragile, but you seem to be concerned with performance, so let's just say slow for now.) If someone tires to avoid an EXISTS sub-query, it precisely because the sub-query is correlated, and that is only an objection because they suspect the correlation will make it slow.
    I was wondering for anti joins, is there any other way to write them besides a NOT EXISTS with a correlated subquery?As the name implies, you can use a join.
    SELECT     d.*
    FROM          scott.dept     d
    LEFT OUTER JOIN     scott.emp     e  ON     d.deptno  = e.deptno
    WHERE     e.deptno     IS NULL
    ;is an anti-join, showing details about the departments that have no employees.
    Essentially what would be the most efficient way of writing an anti join? Or when Im trying to find all the rows that are NOT a common match between two tables.Anytime you can use EXISTS, you can also use IN, or a join. Personally, I tend to use the in the reverse of that order: I'll generally try it with a join first. If that looks like a problem, then I'll try IN. The query above can also be done like this:
    SELECT     *
    FROM     scott.dept
    WHERE     deptno     NOT IN (
                      SELECT  deptno
                      FROM    scott.emp
                      WHERE   deptno   IS NOT NULL   -- If needed
    ;Failing that, I'll try EXISTS.
    Sometimes other methods are useful, too. For example, if we only need to know the deptnos that exist in scott.dept but not scott.emp, and no other information about those departments, then we can say:
    SELECT  deptno
    FROM    scott.dept
        MINUS
    SELECT  deptno
    FROM    scott.emp
    ;

  • Correlated subqueries

    what is the use of correlated subqueries and exists and not exists operator.
    what is correlated update, correlated delete
    thx
    pk

    First step is to look for "correlated" into the on-line doc :
    http://www.oracle.com/pls/db92/db92.drilldown?levelnum=2&toplevel=a96540&method=FULL&chapters=0&book=&wildcards=1&preference=&expand_all=&verb=&word=correlated#a96540
    That may help you.
    Nicolas.

  • Correlated subqueries in webi/designer

    Hi,
    i want to know how correlated subqueries can be achieved in web intelligence/universe.
    If the correlated subquery is in the where clause of the sql, then it can be achieved by creating a predefined query filter in the universe.
    The below is a simple example. In my universe i dont have a join between customers and fact_accounts.
    SELECT
    account_number,
    account_balance,
    (select account_name from customers where account_NO=fa.account_number)
    FROM fact_accounts fa
    WHERE balance_date between '01-jan-2014' and '30-apr-2014'
    how to achieve the above subquery in webi or universe
    Regards

    Would you please confirm that CQL does NOT support correlated sub-queries?

  • Correlated Subqueries Vs Cursor

    Hi all,
    For good performance which one is best amoung Correlated Subqueries or Cursors.(if both table with millions of rec)
    Thanks
    Kalinga

    Blind rule. If something can be done in SQL alone, then it is better in performance that doin git using PL/SQL.
    So using subqueries or JOINS is always better than using cursors (I think you meant nested cursors here).
    Cheers
    Sarma.

  • Correlated subqueries in CQL

    Documentation says EPL supports both simple subqueries as well as correlated subqueries.
    CQL does not accept correlated subqueries as I get the error "Cause: Invalid usage of Reserved CQL Keyword: "SELECT" ".
    I couldn't find anything related to this in CQL Ref doc. Should I go with views for such implementing correlated queries?
    Thanks.

    Would you please confirm that CQL does NOT support correlated sub-queries?

  • Performance Issues with Correlated Subqueries

    Hi,
    We have a problem with the performance of correlated subquery. Please see below the query we use;
    select &ebenecolval, &attribalias
    from freq2 as tab1
    where cnt_rank = (select min(cnt_rank)
    from freq2_&attribcolval as tab2
    where tab1.&ebenecolval = tab2.&ebenecolval);
    (We need to get the minimum of the cnt_rnk from the table freq2 for each ebenecolval attribute)
    The table freq2 has around 12 million records and so the subquery executes for each of the record and there by reduces the performance.
    Can you please suggest any other option to otimize the performance.
    Thanks.

    create a index on (cnt_rank , .&ebenecolval) for the table freq2_&attribcolval and check its performance.
    I am not sure about the improvement but you can give a try.

  • Creating Correlated Subqueries

    I am currently trying to write a query to perform the following:
    For those deactivated agents that are on more than seven missions, change their deactivation date to the earliest deactivation date of all agents who were activated in the same year as the agent you are updating.
    I understand the question but dont know how to go about breaking it down.
    Is there a method for mapping correlated sub-queries?
    Any help appreciated.
    TABLES
    AGENTS
    agent_id primary key
    first_name
    last_name
    location_id foreign key
    activation_date
    deactivation_date
    MISSION_AGENT
    agent_id FK
    mission_id FK
    Some of the mess I have tried already:
    SELECT
    a2.agent_id,
    new.mission_count,
    a2.deactivation_date d_day,
    a2.activation_date a_day
    FROM
    agents a2
    INNER JOIN
    SELECT
    a.agent_id agent_id,
    count(m.mission_id) mission_count
    FROM
    agents a
    INNER JOIN
    missions_agents m
    ON
    a.agent_id=m.agent_id
    WHERE
    deactivation_date is not null
    GROUP BY
    a.agent_id
    ) new
    ON
    a2.agent_id=new.agent_id
    WHERE
    new.mission_count>7
    =========================================================
    SELECT
    d_day
    FROM
    SELECT
    min(deactivation_date) d_day,
    TO_CHAR(activation_date,'YYYY') a_year
    FROM
    agents t2
    GROUP BY
    TO_CHAR(activation_date,'YYYY')
    WHERE
    t2.a_year=t.TO_CHAR(activation_date,'YYYY')

    see if this works...
    SQL> drop table agents
      2  /
    Table dropped.
    SQL> drop table mission_agent
      2  /
    Table dropped.
    SQL> create table agents
      2  (
      3     agent_id                integer primary key,
      4     activation_date         date,
      5     deactivation_date       date
      6  )
      7  /
    Table created.
    SQL> insert into agents values (1,trunc(sysdate, 'year'),null)
      2  /
    1 row created.
    SQL> insert into agents values (2,trunc(sysdate, 'year'),trunc(sysdate, 'year')+6)
      2  /
    1 row created.
    SQL> insert into agents values (3,trunc(sysdate, 'year'),trunc(sysdate, 'year')+5)
      2  /
    1 row created.
    SQL> insert into agents values (4,trunc(sysdate, 'year'),trunc(sysdate, 'year')+4)
      2  /
    1 row created.
    SQL> insert into agents values (5,trunc(sysdate, 'year')-1,trunc(sysdate, 'year')+3)
      2  /
    1 row created.
    SQL> create table mission_agent
      2  (
      3     agent_id                integer,
      4     mission_id              integer
      5  )
      6  /
    Table created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(2,1)
      2  /
    1 row created.
    SQL> insert into mission_agent values(4,2)
      2  /
    1 row created.
    SQL> insert into mission_agent values(4,2)
      2  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> select * from agents
      2  /
      AGENT_ID ACTIVATIO DEACTIVAT
             1 01-JAN-08
             2 01-JAN-08 07-JAN-08
             3 01-JAN-08 06-JAN-08
             4 01-JAN-08 05-JAN-08
             5 31-DEC-07 04-JAN-08
    SQL> select * from mission_agent
      2  /
      AGENT_ID MISSION_ID
             2          1
             2          1
             2          1
             2          1
             2          1
             2          1
             2          1
             2          1
             4          2
             4          2
    10 rows selected.
    SQL> update agents a
      2     set deactivation_date =
      3                    (select (select min(deactivation_date) deactivation_date
      4                               from agents t
      5                              where t.agent_id <> t1.agent_id
      6                                and trunc(t.activation_date,'year') = trunc(t1.activation_date,'year')
      7                                and t.deactivation_date is not null) new_deactivation_date
      8                       from (select a.agent_id, max(a.activation_date) activation_date, max(a.deactivation_date) deactivation_date
      9                               from agents a,
    10                                    mission_agent ma
    11                              where a.agent_id = ma.agent_id
    12                                and deactivation_date is not null
    13                              group by a.agent_id
    14                             having count(1) > 7) t1
    15                      where a.agent_id = t1.agent_id)
    16   where exists
    17             (select null
    18               from (select a.agent_id, max(a.activation_date) activation_date, max(a.deactivation_date) deactivation_date
    19                       from agents a,
    20                            mission_agent ma
    21                      where a.agent_id = ma.agent_id
    22                        and deactivation_date is not null
    23                      group by a.agent_id
    24                     having count(1) > 7) t1
    25              where a.agent_id = t1.agent_id)
    26  /
    1 row updated.
    SQL> select * from agents
      2  /
      AGENT_ID ACTIVATIO DEACTIVAT
             1 01-JAN-08
             2 01-JAN-08 05-JAN-08
             3 01-JAN-08 06-JAN-08
             4 01-JAN-08 05-JAN-08
             5 31-DEC-07 04-JAN-08
    SQL>Thanks,
    Karthick.

  • Correlated subqueries in an UPDATE statement

    SQL> desc class
    Name Null? Type
    ITEM_NO******************************VARCHAR2(5)
    CLASSIFICATION********************VARCHAR2(255)
    MIN_RANGE**************************VARCHAR2(14)
    MAX_RANGE_CNTRL****************VARCHAR2(14)
    SQL> desc items_test
    Name Null? Type
    ITEM_NO****************************NOT NULL NUMBER(4)
    CLASS_TITLE**********************NOT NULL VARCHAR2(50)
    RATE_TYPE ***********************NOT NULL VARCHAR2(1)
    MAXIMUM_SALARY**************NUMBER(8,2)
    I am trying to update values of "MAXIMUM_SALARY" in items_test table.
    Condition should be where rate_type = 'A' and item_no of items table equal to item_no of class table. Then MAXIMUM_SALARY of items table should be replace by MAX_RANGE_CNTRL of class table.
    But I am getting error,
    pl have a look at it.
    SQL> update items_test X
    2 set MAXIMUM_SALARY =(select Y.MAX_RANGE_CNTRL
    3 from class Y
    4 where X.item_no = Y.item_no)
    5 where x.rate_type = 'A';
    set MAXIMUM_SALARY =(select Y.MAX_RANGE_CNTRL
    ERROR at line 2:
    ORA-01722: invalid number
    Any help will be appreciated.
    D

    yes, same thing
    SQL> update items_test X
    2 set MAXIMUM_SALARY =(select to_number(Y.MAX_RANGE_CNTRL)
    3 from class Y
    4 where X.item_no = Y.item_no)
    5 where x.rate_type = 'A';
    set MAXIMUM_SALARY =(select to_number(Y.MAX_RANGE_CNTRL)
    ERROR at line 2:
    ORA-01722: invalid number
    I created another table of prototype of class but with corrcet datatype but not able to insert values from class.
    SQL> desc classification
    Name Null? Type
    ITEM_NO*********************************** NUMBER(4)
    CLASSIFICATION ************************ VARCHAR2(255)
    MIN_RANGE ********************************NUMBER(14)
    MAX_RANGE_CNTRL********************* NUMBER(14)
    SQL> insert into classification
    2 select * from class;
    select * from class
    ERROR at line 2:
    ORA-01722: invalid number

  • Equivalent for TOP 1 of SQL Server used in subqueries

    Hi all,
    I am trying to migrate a sql query from SQL Server to Oracle 9i, which uses the SQL Server TOP keyword in correlated subqueries.
    How should I write it in Oracle?
    The query is more complicated, but in principle looks like:
    SELECT TAB1.t1_id, TAB2_t2_id,
    ISNULL((select top 1 val_num
    from values where values.val_id = TAB1.val_id ) ,0),
    TAB1.date,
         (select top 1 TAB3.t3_id from TAB3 where TAB3.name = TAB1.name)
    FROM TAB1, TAB2
    WHERE TAB1.org_id = TAB2.org_id
         AND TAB1.date > TO_DATE('2006-01-01', 'YYYY-MM-DD')
         TAB2.required IS NOT NULL
    If I would remove in each subquery the "top 1" and add "and rownum = 1", it will not work.
    Any suggestions?
    Thanks,
    Paul

    http://www.ispirer.com/doc/sqlways38/Output/SQLWays-1-044.html

  • Flattening, correlated subquery

    Hi,
    The following fields are key values on a table, with example data :
    EMPNO DATE ACTION
    1234 6/6/05 HIR
    1234 6/6/05 XFR
    1234 6/10/05 DTA
    1234 6/22/05 XFR
    1234 7/30/05 TER
    3456 6/6/05 HIR
    etc.
    I need to create a view to show the previous 5 rows of history per employee but flattened to be one line per Employee Number (EMPNO).
    So the view would be something like :
    EMPNO ACTION1 DATE1 ACTION2 DATE2 ACTION3 DATE3 (etc.)
    1234 HIR 6/6/05 XFR 6/6/05 DTA 6/10/05
    I have thought of aliasing the table and then using correlated subqueries, but this got complicated joining to >2 tables. Since joining to table 2 required that DATE1 <> DATE2 or ACTION1 <> ACTION2. But then alias 3 becomes more convoluted and then 4 and 5 OTT.
    I also looked at some rownum trickery to get the <=5 rows, but I could not get this working.
    What is the best solution for this problem ? Note that it does have to be a pure view, not PL/SQL etc.
    Thanks,
    T0rrent

    I think you are after this. You must know the number of actions per output row. In this case five:
    drop table t;
    create table t( empno number, x_date date, action varchar2(3));
    insert into t values (1234, to_date('6/6/05 01:00','mm/dd/yy hh:mi'),'HIR'); --need to have unique date values per empno
    insert into t values (1234, to_date('6/6/05 02:00','mm/dd/yy hh:mi'),'XFR'); --need to have unique date values per empno
    insert into t values (1234, to_date('6/10/05','mm/dd/yy'),'DTA');
    insert into t values (1234, to_date('6/22/05','mm/dd/yy'),'XFR');
    insert into t values (1234, to_date('7/30/05','mm/dd/yy'),'TER');
    insert into t values (3456, to_date('6/6/05','mm/dd/yy'),'HIR');
    commit;
    create or replace view tv as
      select empno, x_date, action, dense_rank() over( partition by empno order by x_date ) e_rank
      from t
      order by empno;
    SELECT  empno,
            max( decode( e_rank, 1, x_date||' '||action)) e_act1,
            max( decode( e_rank, 2, x_date||' '||action)) e_act2,
            max( decode( e_rank, 3, x_date||' '||action)) e_act3,
            max( decode( e_rank, 4, x_date||' '||action)) e_act4,
            max( decode( e_rank, 5, x_date||' '||action)) e_act5
    FROM    tv
    group by empno;
         EMPNO E_ACT1        E_ACT2        E_ACT3        E_ACT4        E_ACT5
          1234 06-JUN-05 HIR 06-JUN-05 XFR 10-JUN-05 DTA 22-JUN-05 XFR 30-JUL-05 TER
          3456 06-JUN-05 HIR

  • Correlated Subquery Issue

    the following sample is from ORACLE DATABASE 10g SQL
    i don't understand how it works, the bellow is the table and the query
    SELECT Product_id pid, product_type_id ptid, name, price
    FROM products
    PID PTID NAME PRICE
    1 1 Modern Science 19.95
    2 1 Chemistry 30
    3 2 Supernova 25.99
    4 2 Tank War 13.95
    5 2 Z Files 49.99
    6 2 2412: The Return 14.95
    7 3 Space Force 9 13.49
    8 3 From Another Planet 12.99
    9 4 Classical Music 10.99
    10 4 Pop 3 15.99
    11 4 Creative Yell 14.99
    PID PTID NAME PRICE
    12 My Front Line 13.49
    the query
    SELECT product_id pid, product_type_id ptid, name, price
    FROM products outer
    WHERE price >
    (SELECT AVG(price)
    FROM products inner
    WHERE inner.product_type_id = outer.product_type_id)
    PID PTID NAME PRICE
    2 1 Chemistry 30
    5 2 Z Files 49.99
    7 3 Space Force 9 13.49
    10 4 Pop 3 15.99
    11 4 Creative Yell 14.99
    what i don't understand is HOW and WHEN the AVG function works and HOW AVG() function knows to calculate the average by grouping the PTID not the average of ALL PRICE column.
    tks for helping in advance

    The subquery
    (SELECT AVG(price)
       FROM products inner
      WHERE inner.product_type_id = outer.product_type_id)knows to create an average of all the products with the same product type because of the WHERE clause, which limits the rows returned to those with the product_type_id in the outer.
    Conceptually, what happens is
    - the outer query gets the first row of the table (PID=1)
    - it grabs the price (19.95)
    - now, it runs the subquery to determine whether this is above average
    - the subquery sees that outer.product_type_id is 1, so the WHERE clause eliminates all but the first two rows (PID 1&2). The average of 19.95 and 30 is 24.975.
    - Since the price of the first row is not greater than 24.975, Oracle knows that it does not meet the conditions of the WHERE clause in the outer query.
    - Repeat for each row in the outer query
    Obviously, since Oracle is doing set-based processing, it may not work exactly this way internally. Conceptually, though, this is how correlated subqueries work.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Correlated subquery execution problem

    Hi
    In correlated subqueries which query executed first whether the inner query or outer query i.e while oracle processing the query
    give me example
    thanx
    asp

    I would say the outer query would be executed first as the inner query is dependant upon that but I guess in some circumstances the CBO will turn this rule on its head
    SQL> select ename from emp
      2  where exists ( select null from dept where dept.deptno = emp.deptno )
      3  /
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=14 Bytes=16
              8)
       1    0   NESTED LOOPS (SEMI) (Cost=4 Card=14 Bytes=168)
       2    1     TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 Byt
              es=126)
       3    1     INDEX (UNIQUE SCAN) OF 'PK_DEPT' (INDEX (UNIQUE)) (Cost=
              1 Card=7 Bytes=21)
      1  select ename from emp
      2* where not exists ( select null from dept where dept.deptno = emp.deptno )
    SQL> /
    no rows selected
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=1 Bytes=12)
       1    0   NESTED LOOPS (ANTI) (Cost=4 Card=1 Bytes=12)
       2    1     TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 Byt
              es=126)
       3    1     INDEX (UNIQUE SCAN) OF 'PK_DEPT' (INDEX (UNIQUE)) (Cost=
              1 Card=7 Bytes=21)

  • How does oracle execute a correlated subquery .... some confusion

    How does oracle 10g execute a correlated subquery?
    I read some articles online & i am a little confused.
    example:
    select * from emp e
    where e.deptno in (select d.deptno from dept d
    where e.deptno = d.deptno);
    My questions .......
    1.In the above example, does oracle read the entire outer table first and then run the inner query using the rows returned by the outer query?
    I read in some articles that they execute simultaneously.
    How does this work?
    2.Should the inner query have lesser amount of rows compared to the outer query for a good performance?
    3.Can every correlated subquery be converted to a join and if so which one to use?
    Truly appreciate any inputs on how oracle executes it at the backend.
    Thanks in advance.

    user10541890 wrote:
    How does oracle 10g execute a correlated subquery?
    I read some articles online & i am a little confused.
    example:
    select * from emp e
    where e.deptno in (select d.deptno from dept d
    where e.deptno = d.deptno);
    My questions .......
    1.In the above example, does oracle read the entire outer table first and then run the inner query using the rows returned by the outer query?
    I read in some articles that they execute simultaneously.
    How does this work?SQL is not a procedural language. SQL code specifies what the system sill do, not how the system wlll do it; that's entirely up to the system.
    What does it matter to you whether the two are done together, or if one is completed before the other begins?
    The system will probably choose to run ucorellated subqueiris only once, and correlated queries multiple times as needed.
    2.Should the inner query have lesser amount of rows compared to the outer query for a good performance?That usually doesn't matter.
    It some cases, you may want to consider whether the subquery is correlated or not. If the subquery is very costly, and produces, say, 1 million rows, but you know the main query will only produce about 5 rows, then you may want to do a correlated subquery rather than an uncorrelated one.
    3.Can every correlated subquery be converted to a join and if so which one to use?I believe so.
    Use whichever is easier to code and debug. That will change depnding on the data and the requirements.
    If performance is an issue, try different ways. Usually, where I've noticed a big difference, join was fastest.
    By the way, it's unusual to have a correlated IN-subquery.
    Usually IN-subqueris are uncorrelated, like this:
    select  *
    from      emp     e
    where     e.deptno     in ( select  d.deptno
                        from    dept     d
                      );(This and the queries below produce the same resutls as your original query.)
    Correlated subqueries are usually used for scalar subqueries or EXISTS subqueries, like this:
    select  *
    from      emp     e
    where     EXISTS ( select  d.deptno
               from    dept     d
                    where   e.deptno = d.deptno
                );To do the same thing with a join:
    select  e.*
    from      emp     e
    join     dept     d     on     e.deptno     = d.deptno
    ;assuming dept.deptno is unique.

  • Corelated subqueries

    can u please let me know the differences between join and correlated subqueries in oracle

    Please read about [url http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/queries8.htm#2054088]Using Subqueries and [url http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/queries7.htm#2054014]Joins in the manual.

Maybe you are looking for

  • Aperture Import window

    With the Aperture import window open and a memory card in a reader, I have at top left two option. One is the select the computer itself as the source and the other is the memory card. If I select the computer, at the bottom of the window I get pane

  • Has this happened to anyone else? if so how did you fix it?

    my computer doesn't start up right. I start it, goes to startup screen and then either stays there or a black screen pops up and says "job reset will occur after ## more consecutive failures" and then it stops doing everything.

  • Lightjet Print Sharpening

    I do all of my personal stuff on large format Epson inkjets. No problem there with Lightroom. Great output. For years I never take a camera to family events to avoid having to supply them...know what I mean. These guys want (for the most part) 4x6s 5

  • Urgent Need in Dallas Texas for a Sr. Oracle BPEL Developer

    $$$$$$$$$$$$ I have an urgent need for a Sr, Oracle BPEL Developer in the Dallas Texas area. With this position, you can interview and start immediately. If you are interested or know of anyone looking please send my way. Or know of companies that us

  • How do I upgrade from OSX 10.7.2 toOSX 10.9?

    How do I upgrade from OSX 10.7 to OSX 10.9?