Oracle Equi Join Query

Can sombody tell me the difference betweeen Query 1 * Query 2. They give the same result. Let me know keeping performance in mind which one should be used.
create table x (id number, name varchar2(100))
create table y (id number, name varchar2(100))
create table z (id number, name varchar2(100))
insert into x values(1,'test1')
insert into x values(2,'test2')
insert into x values(3,'test3')
insert into x values(4,'test4')
insert into y values(1,'test5')
insert into y values(3,'test6')
insert into z values(1,'test7')
insert into z values(4,'test8')
QUERY1
select x.id,y.id,z.id,x.name,y.name,z.name
from x,y,z
where
x.id = y.id
and x.id = z.id
and (x.id =2 or x.id = 1)
QUERY2
select x.id,y.id,z.id,x.name,y.name,z.name
from x
JOIN y
ON x.id = y.id
JOIN z
ON x.id = z.id
and (x.id =2 or x.id = 1)

Sorry i forgot the integrity constraints:
create table x (id number, name varchar2(100))
create table y (id number, name varchar2(100))
create table z (id number, name varchar2(100))
alter table x add constraint x_pk primary key(id)
alter table y add constraint y_fk foreign key(id)
REFERENCES X(ID)
alter table z add constraint z_fk foreign key(id)
REFERENCES X(ID)
insert into x values(1,'test1')
insert into x values(2,'test2')
insert into x values(3,'test3')
insert into x values(4,'test4')
insert into y values(1,'test5')
insert into y values(3,'test6')
insert into z values(1,'test7')
insert into z values(4,'test8')
select x.id,y.id,z.id,x.name,y.name,z.name
from x,y,z
where
x.id = y.id
and x.id = z.id
and (x.id =2 or x.id = 1)
select x.id,y.id,z.id,x.name,y.name,z.name
from x
JOIN y
ON x.id = y.id
JOIN z
ON x.id = z.id
and (x.id =2 or x.id = 1)

Similar Messages

  • Equi join-same output get from subquery??

    Hi,
    I written one equi-join query, same ouput can i get from sub query??.
    select e.empno,e.ename from emp e,dept d
    where e.deptno=d.deptno;
    Regards,
    Venkat.

    Really have no idea what you mean.
    If you need those d. columns, just add them to your select list.
    There's no subquery here at all.

  • Outer join query for SQL server from Oracle

    Hi All,
    My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
    In my oracle database I have a DBLink emp.world for SQL Server database.
    I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
    Query is given below:
    SELECT
            a."EmpID" as "Employee ID",
            a."EmpStatus" "Employee Status"
            b."EmpSub" as "Employee Subjects"
    FROM
            [email protected] a
            left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY  a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
    Samples are given below:
    Run from Oracle
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    104                   Inactive                  Chemistry
    Run form SQL Server
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    103                 Active                       NULL
    104             Inactive            ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
    I am using oracle database 10gR2 and SQL Server 2005.
    Please Help.
    Thanks.

    SELECT
    a."EmpID" as "Employee ID",
    a."EmpStatus" "Employee Status"
    b."EmpSub" as "Employee Subjects"
    FROM
    [email protected] a
    left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY a."EmpID";
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
    From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know.

  • Equi join as well as outer join

    Hi all,
    I have two table. They have common fields case_id and issuer_id.
    I want to retrieve the data from two tables first based on case_id(equi join) and then issuer_id(outer join). The query like this
    select t1.case_id,t1.case_name,t2.issuer_name from case t1,issuers t2
    where t1.case_id=t2.case_id and t1.issuer_id=t2.issuer_id(+)
    The above query displays error
    so, My query first gets the data based on equijoin , then i want to apply outer join on that same tables.
    plz try to solve the above problem

    SQL> create table mycase
      2  as
      3  select 1 case_id, 'NAME1' case_name, 1 issuer_id from dual union all
      4  select 2, 'NAME2', 2 from dual union all
      5  select 3, 'NAME3', 3 from dual union all
      6  select 4, 'NAME3', 4 from dual
      7  /
    Tabel is aangemaakt.
    SQL> create table issuers
      2  as
      3  select 1 case_id, 1 issuer_id, 'ISSUER1' issuer_name from dual union all
      4  select 2, 3, 'ISSUER2' from dual union all
      5  select 3, 4, 'ISSUER3' from dual union all
      6  select 4, 6, 'ISSUER4' from dual
      7  /
    Tabel is aangemaakt.
    SQL> select t1.case_id,t1.case_name,t2.issuer_name from mycase t1,issuers t2
      2  where t1.case_id=t2.case_id and t1.issuer_id=t2.issuer_id(+)
      3  /
                                   CASE_ID CASE_ ISSUER_
                                         1 NAME1 ISSUER1
    1 rij is geselecteerd.The above query doesn't make sense: the outer join predicate says "if I don't find a matching issuer_id, Oracle please make up an entire null issuer record for this one". Then the other predicate says "t1.case_id=t2.case_id" where a null value for t2.case_id will never match t1.case_id and will be excluded from the result set. Effectively you could drop the plus sign in this query to achieve the same result.
    Maybe you want the query below?
    SQL> select t1.case_id
      2       , t1.case_name
      3       , case t1.issuer_id
      4         when t2.issuer_id then t2.issuer_name
      5         else null
      6         end issuer_name
      7    from mycase t1
      8       , issuers t2
      9   where t1.case_id = t2.case_id
    10  /
                                   CASE_ID CASE_ ISSUER_
                                         1 NAME1 ISSUER1
                                         2 NAME2
                                         3 NAME3
                                         4 NAME3
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • How can I perform this kind of range join query using DPL?

    How can I perform this kind of range join query using DPL?
    SELECT * from t where 1<=t.a<=2 and 3<=t.b<=5
    In this pdf : http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,
    It shows how to perform "Two equality-conditions query on a single primary database" just like SELECT * FROM tab WHERE col1 = A AND col2 = B using entity join class, but it does not give a solution about the range join query.

    I'm sorry, I think I've misled you. I suggested that you perform two queries and then take the intersection of the results. You could do this, but the solution to your query is much simpler. I'll correct my previous message.
    Your query is very simple to implement. You should perform the first part of query to get a cursor on the index for 'a' for the "1<=t.a<=2" part. Then simply iterate over that cursor, and process the entities where the "3<=t.b<=5" expression is true. You don't need a second index (on 'b') or another cursor.
    This is called "filtering" because you're iterating through entities that you obtain from one index, and selecting some entities for processing and discarding others. The white paper you mentioned has an example of filtering in combination with the use of an index.
    An alternative is to reverse the procedure above: use the index for 'b' to get a cursor for the "3<=t.b<=5" part of the query, then iterate and filter the results based on the "1<=t.a<=2" expression.
    If you're concerned about efficiency, you can choose the index (i.e., choose which of these two alternatives to implement) based on which part of the query you believe will return the smallest number of results. The less entities read, the faster the query.
    Contrary to what I said earlier, taking the intersection of two queries that are ANDed doesn't make sense -- filtering is the better solution. However, taking the union of two queries does make sense, when the queries are ORed. Sorry for the confusion.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Equi Join and Outer join using outer keyword

    Hi,
    First lets take the create statment for scott schema.
    create table scott.emp_details(empno number, bonus_date date);
    Insert Into Scott.Emp_Details Values(7369, To_Date('01-jan-2013'));
    Insert Into Scott.Emp_Details Values(7499, To_Date('05-jan-2013'));
    Insert Into Scott.Emp_Details Values(7521, To_Date('10-jan-2013'));
    Insert Into Scott.Emp_Details Values(7566, To_Date('01-feb-2013'));
    Insert Into Scott.Emp_Details Values(7654, To_Date('05-feb-2013'));
    commit;lets also consider the basic scott.emp and scott.dept tables
    Now I would like to equi join emp table deptno col with dept table deptno col and left outer join emp table hiredate with emp_details bonus_date and empno col in emp_details can be joined(Equi Join) with empno col of emp table if needed .The outer join has to be placed using the keyword (left/right)outer join
    The select statement can have all the detials of emp table .The requirement may look weird but we have some such requirement.
    Please suggest

    Hi,
    sri wrote:
    Hi,
    First lets take the create statment for scott schema.
    create table scott.emp_details(empno number, bonus_date date);
    Insert Into Scott.Emp_Details Values(7369, To_Date('01-jan-2013'));
    Insert Into Scott.Emp_Details Values(7499, To_Date('05-jan-2013'));
    Insert Into Scott.Emp_Details Values(7521, To_Date('10-jan-2013'));
    Insert Into Scott.Emp_Details Values(7566, To_Date('01-feb-2013'));
    Insert Into Scott.Emp_Details Values(7654, To_Date('05-feb-2013'));
    commit;
    It's best not to create your own tables in Oracle-supplied schemas, such as SCOTT. Use your own schema for your own tables.
    lets also consider the basic scott.emp and scott.dept tablesI see; you're using the standard scott,emp and scott.dept tables, plus the emp_details table you posted above.
    Now I would like to equi join emp table deptno col with dept table deptno col and left outer join emp table hiredate with emp_details bonus_date and empno col in emp_details can be joined(Equi Join) with empno col of emp table if needed .The outer join has to be placed using the keyword (left/right)outer join
    The select statement can have all the detials of emp table .The requirement may look weird but we have some such requirement.
    Please suggestThanks for posting the sample data. Don't forget to post the exact output you want from that sample data.
    Do you want something like this?
    `    EMPNO ENAME          DEPTNO DNAME          BONUS_DAT
          7369 SMITH              20 RESEARCH       01-JAN-13
          7499 ALLEN              30 SALES          05-JAN-13
          7521 WARD               30 SALES          10-JAN-13
          7566 JONES              20 RESEARCH       01-FEB-13
          7654 MARTIN             30 SALES          05-FEB-13
          7698 BLAKE              30 SALES
          7782 CLARK              10 ACCOUNTING
          7788 SCOTT              20 RESEARCH
          7839 KING               10 ACCOUNTING
          7844 TURNER             30 SALES
          7876 ADAMS              20 RESEARCH
          7900 JAMES              30 SALES
          7902 FORD               20 RESEARCH
          7934 MILLER             10 ACCOUNTING
                                  40 OPERATIONSIf so, here's one way to do it:
    SELECT       e.empno, e.ename     -- or whatever columns you want
    ,       d.deptno, d.dname     -- or whatever columns you want
    ,       ed.bonus_date
    FROM           scott.dept  d
    LEFT OUTER JOIN      scott.emp   e   ON  e.deptno     = d.deptno
    LEFT OUTER JOIN      emp_details ed      ON  ed.empno     = e.empno
    ORDER BY  e.empno
    ;

  • Inner Join. How to improve the performance of inner join query

    Inner Join. How to improve the performance of inner join query.
    Query is :
    select f1~ablbelnr
             f1~gernr
             f1~equnr
             f1~zwnummer
             f1~adat
             f1~atim
             f1~v_zwstand
             f1~n_zwstand
             f1~aktiv
             f1~adatsoll
             f1~pruefzahl
             f1~ablstat
             f1~pruefpkt
             f1~popcode
             f1~erdat
             f1~istablart
             f2~anlage
             f2~ablesgr
             f2~abrdats
             f2~ableinh
                from eabl as f1
                inner join eablg as f2
                on f1ablbelnr = f2ablbelnr
                into corresponding fields of table it_list
                where f1~ablstat in s_mrstat
                %_HINTS ORACLE 'USE_NL (T_00 T_01) index(T_01 "EABLG~0")'.
    I wanted to modify the query, since its taking lot of time to load the data.
    Please suggest : -
    Treat this is very urgent.

    Hi Shyamal,
    In your program , you are using "into corresponding fields of ".
    Try not to use this addition in your select query.
    Instead, just use "into table it_list".
    As an example,
    Just give a normal query using "into corresponding fields of" in a program. Now go to se30 ( Runtime analysis), and give the program name and execute it .
    Now if you click on Analyze button , you can see, the analysis given for the query.The one given in "Red" line informs you that you need to find for alternate methods.
    On the other hand, if you are using "into table itab", it will give you an entirely different analysis.
    So try not to give "into corresponding fields" in your query.
    Regards,
    SP.

  • Oracle date parameter query not working?

    http://stackoverflow.com/questions/14539489/oracle-date-parameter-query-not-working
    Trying to run the below query, but always fails even though the parameter values matches. I'm thinking there is a precision issue for :xRowVersion_prev parameter. I want too keep as much precision as possible.
    Delete
    from CONCURRENCYTESTITEMS
    where ITEMID = :xItemId
    and ROWVERSION = :xRowVersion_prev
    The Oracle Rowversion is a TimestampLTZ and so is the oracle parameter type.
    The same code & query works in Sql Server, but not Oracle.
    Public Function CreateConnection() As IDbConnection
    Dim sl As New SettingsLoader
    Dim cs As String = sl.ObtainConnectionString
    Dim cn As OracleConnection = New OracleConnection(cs)
    cn.Open()
    Return cn
    End Function
    Public Function CreateCommand(connection As IDbConnection) As IDbCommand
    Dim cmd As OracleCommand = DirectCast(connection.CreateCommand, OracleCommand)
    cmd.BindByName = True
    Return cmd
    End Function
    <TestMethod()>
    <TestCategory("Oracle")> _
    Public Sub Test_POC_Delete()
    Dim connection As IDbConnection = CreateConnection()
    Dim rowver As DateTime = DateTime.Now
    Dim id As Decimal
    Using cmd As IDbCommand = CreateCommand(connection)
    cmd.CommandText = "insert into CONCURRENCYTESTITEMS values(SEQ_CONCURRENCYTESTITEMS.nextval,'bla bla bla',:xRowVersion) returning ITEMID into :myOutputParameter"
    Dim p As OracleParameter = New OracleParameter
    p.Direction = ParameterDirection.ReturnValue
    p.DbType = DbType.Decimal
    p.ParameterName = "myOutputParameter"
    cmd.Parameters.Add(p)
    Dim v As OracleParameter = New OracleParameter
    v.Direction = ParameterDirection.Input
    v.OracleDbType = OracleDbType.TimeStampLTZ
    v.ParameterName = "xRowVersion"
    v.Value = rowver
    cmd.Parameters.Add(v)
    cmd.ExecuteNonQuery()
    id = CType(p.Value, Decimal)
    End Using
    Using cmd As IDbCommand = m_DBTypesFactory.CreateCommand(connection)
    cmd.CommandText = " Delete from CONCURRENCYTESTITEMS where ITEMID = :xItemId and ROWVERSION = :xRowVersion_prev"
    Dim p As OracleParameter = New OracleParameter
    p.Direction = ParameterDirection.Input
    p.DbType = DbType.Decimal
    p.ParameterName = "xItemId"
    p.Value = id
    cmd.Parameters.Add(p)
    Dim v As OracleParameter = New OracleParameter
    v.Direction = ParameterDirection.Input
    v.OracleDbType = OracleDbType.TimeStampLTZ
    v.ParameterName = "xRowVersion_prev"
    v.Value = rowver
    v.Precision = 6 '????
    cmd.Parameters.Add(v)
    Dim cnt As Integer = cmd.ExecuteNonQuery()
    If cnt = 0 Then Assert.Fail() 'should delete
    End Using
    connection.Close()
    End Sub
    Schema:
    -- ****** Object: Table SYSTEM.CONCURRENCYTESTITEMS Script Date: 1/26/2013 11:56:50 AM ******
    CREATE TABLE "CONCURRENCYTESTITEMS" (
    "ITEMID" NUMBER(19,0) NOT NULL,
    "NOTES" NCHAR(200) NOT NULL,
    "ROWVERSION" TIMESTAMP(6) WITH LOCAL TIME ZONE NOT NULL)
    STORAGE (
    NEXT 1048576 )
    Sequence:
    -- ****** Object: Sequence SYSTEM.SEQ_CONCURRENCYTESTITEMS Script Date: 1/26/2013 12:12:48 PM ******
    CREATE SEQUENCE "SEQ_CONCURRENCYTESTITEMS"
    START WITH 1
    CACHE 20
    MAXVALUE 9999999999999999999999999999

    still not comming...
    i have one table each entry is having only one fromdata and one todate only
    i am running below in sql it is showing two rows. ok.
      select t1.U_frmdate,t1.U_todate  ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID  AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf 
       from  [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
       on t0.DocEntry = t1.DocEntry
       inner join ohem t2
       on t2.empID = t0.U_empid  where  t0.U_empid between  '830' and  '850'  and t1.U_frmdate ='20160801'  and  t1.u_todate='20160830'
    in commond promt
      select t1.U_frmdate,t1.U_todate  ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID  AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf 
       from  [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
       on t0.DocEntry = t1.DocEntry
       inner join ohem t2
       on t2.empID = t0.U_empid  where  t0.U_empid between  {?FromEmid} and  {?ToEmid} and t1.U_frmdate ={?FDate} and  t1.u_todate={?TDate}
    still not showing any results..

  • How to tune the performance of Oracle SQL/XML query?

    Hi all,
    I am running Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    ajallen wrote:
    Why not something more like
    SELECT *
    FROM fact1 l,
    FULL OUTER JOIN fact1 d
    ON l.company = d.company
    AND l.transactiontypeid = 1
    AND d.transactiontypeid = 2;
    Because this is not an equivalent of the original query.
    drop table t1 cascade constraints purge;
    drop table t2 cascade constraints purge;
    create table t1 as select rownum t1_id from dual connect by level <= 5;
    create table t2 as select rownum+2 t2_id from dual connect by level <= 5;
    select * from (select * from t1 where t1_id > 2) t1 full outer join t2 on (t1_id = t2_id);
    select * from t1 full outer join t2 on (t1_id = t2_id and t1_id > 2);
         T1_ID      T2_ID
             3          3
             4          4
             5          5
                        6
                        7
         T1_ID      T2_ID
             1
             2
             3          3
             4          4
             5          5
                        6
                        7

  • Cartesian Join query optimization

    Hello Experts!
    I have a question about cartesian join query which might look a bit weird.
    Assume the SQL query like that:
    SELECT DISTINCT A.NAME
    FROM A, B, C;
    Here we have cartesian join for 3 tables A, B and C.
    It looks to me, in order to get the result for such a particular SQL tables/sets B and C need to be accessed only to ensure they return at least 1 row (otherwise result set is empty), query table A, but there is no actual need to join the data.
    If you run such a query Oracle is doing full table scans and actually joins the data.
    Yes, DBMS is doing exactly what you are asking for, but I wonder if there is any way (SQL hint or db parameter or anything else) to enforce more optimal access path here?
    Obvious solution to remove B and C tables from the SELECT statement is not acceptable. :-)
    Thank you!

    Your statement in the other thread indicates you don't understand how the BI prompts actually work because you say you want it to do something that doesn't make sense for it to do.
    Of course Product and Account levels will be constrained to the interval you specified. It wouldn't make sense for them not to be. Because that would mean returning data for based on product and account levels that has a different open data range than what you specified.
    All UI prompt dialogs I have seen use AND relationships between the parameters. If there are three parameters (A, B, C) then the ultimate relationship is 'A AND B AND C'; not 'A OR (B AND C)', 'A AND (B OR C)', 'A OR (B OR C).
    Unless the tool allows you to select OR relationships you need to use a separate dialog box (parameter dialog) for each condition set.:-)
    I understand how BI prompts work and basically agree on your comment, but there are two problems here:
    1. I need to convince the customer his original requirements are not valid. Customer want it to work different way and there are some reasons why.
    2. There are pretty large dimensions and fact tables used here, so when I choose filter criteria for the Product (which is small table) to populate/recalculate prompt values, large SR dimension and fact tables are joined too, and if there are Account dimension filters added, huge Account dimension will be added as well. This looks to be a bit sub-optimal for just populating the Product prompt values.
    Of course, technically this is solvable, but requires to put some extra effort and does not solve the 1st issue.
    That other link doesn't explain the sample code you posted in this thread. Post the actual query that is being generated and the query that you want to actually use.This is what is generated:
    >
    select distinct T311691.X_CUST_SUBTYPE as c1
    from
    WC_LOV_SR_AREA_H T311695,
    WC_LOV_PROD_H T311687,
    WC_LOV_CUST_TYPE_H T311691,
    W_SRVREQ_D T302384 /* Dim_W_SRVREQ_D */
    where ( T311687.LEV1 = 'Product X' and T311691.X_CUST_TYPE = 'Business' and T302384.OPEN_DT between TO_DATE('2012-03-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2012-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
    order by c1
    >
    This is what is actually needed to query this data:
    >
    select distinct T311691.X_CUST_SUBTYPE as c1
    from
    WC_LOV_CUST_TYPE_H T311691
    where ( T311691.X_CUST_TYPE = 'Business' )
    order by c1

  • On outer Join Query

    Hi All,
    I have a outer join query which is creating bottlenecks and increasing the cost of the query, the plan of the query is pretty awkward with multiple nested outer loop joins. Though its the requirement for me to write such a query. I would like to get advice from the SQL community to know whether we can rewrite the query in any other way so that it reduces the cost and there is considerable improvement in the plan.
    For example can we rewrite this query to ensure we get the same output with much improved plan and cost.
    Basically i want to avoid thsi left Outer Join. Can we do this any way with lesser cost and consistent gets.
    Here is a sample query.
    Select e.Empno,e.Ename,e.Sal, D.Dname,D.deptno
    From
    Emp e, Dept d
    Where e.Deptno(+) = d.Deptno
    Thanks in advance

    You haven't given us much to work with, not even your Oracle version. So, start with these:
    When your query takes too long
    When your query takes too long ...
    How to Post a SQL statement tuning request
    HOW TO: Post a SQL statement tuning request - template posting

  • Equi JOINS vs SUBQUERY

    May I know the difference in processing time or execution time when we use the Equi-Join and when we use Suquery in Search criteria.
    Plz help, because the query (137 query) which we have written contains Subquery and fetching thousands of records, taking processing time 10 min.
    We also altered the query batch with Equi-Joins and it is taking only 5 min. So can we say that Equi-Joins are much faster then Subquery.
    Do Reply.
    Thank in Advance
    Vishal
    (Database Developer)

    In theory, it shouldn't matter. If you are able to figure out how to unnest subquery, the optimiser query transformation engine would likely to be able to do that that as well.

  • Help needed on Equi join?

    I have 3 views and in that common column datatype is varchar. I have to use equi join to get the data from 3 view.
    In 3 views total records are 23668,111,3033
    when i wrote the join i am getting the output in lakhs. I don't whether the output is right or not.
    Please guide me on this.
    Waiting for valuable replies.
    Thanks and Regards
    Sridhar.

    If you're returning more rows than you expect, it means that you have 1 to many or even many to many join.
    I would re-write your query this way:
    SELECT p.facid, rxs.rxno, rxs.rxbatch,patlname,patfname,InitReview,LabelPrintedOn,packed,PlacedInTote,street1,zip,BatchDescr
    FROM Patients p
    INNER JOIN rX.dbo.rxs rxs
    ON p.facid = rxs.FacID
    INNER JOIN rX.dbo.RxBatches Batch
    ON p.facid= Batch.FacID
    WHERE p.facid in('CRH','LSRX') and Batch.batchdescr LIKE 'STAT%'
    I also suggest to add alias to every column in your query. Even if the column belongs to a particular table, adding the alias in front of it will make maintenance of this query much easier. Say, I have no idea if BatchDescr field belongs to the second table
    RxBatches or rxS, so I made a guess.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Join Query hanging

    hi experts,
    please help on this, we have migrated database from 10g to 11.2.0.3 , Everything went sccessful but one of the simple join query hanging occasionally in new upgraded database. is there any known issue or anything need to add after migration for sqls?,also before migration its was executed without any issues. that query is joining and fetching from two more tables . is there any generic reason please provide that would be helpful to analyze, Thanks in Advance.

    why wasn't this discovered during testing prior to the upgrade?
    does new DB have current statistics?
    How do I ask a question on the forums?
    https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360002

  • Join query getting poor performance

    Hi,
    This is my join query to retriving data , i had a problem from this, its getting very slow to retrive data, even i used in report builder, it could not build the report.
    From this select statement i've using three tables ,
    please help and have suggestion to tune my query better fast and give some new idea , but i'm using oracle 8i.
    select a.customer_code customer, c.name name, c.place place, a.product_code product, b.quantity ord_qty, nvl(b.delivery_district_code,c.district_code) district, nvl(b.delivery_town_code,c.town_code) town
    from order_book a, order_book_detail b, customer c
    where a.region_code = b.region_code
    and a.order_book_form_no = b.order_book_form_no
    and a.customer_code = c.customer_code
    and c.division_code = 34
    and a.region_code = 10
    and c.state_code = 1
    and a.order_book_form_date = '18-OCT-2007'
    and nvl(c.classification_code,'N') = 'S'
    order by 1;
    regards
    venki

    why nobody answering me.Because you gave us nothing to investigate. Please read [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]this thread and post a tkprof output here. For an explain plan in 8i, you could "set autotrace on explain" in SQL*Plus.
    Regards,
    Rob.

Maybe you are looking for

  • Error opening report using WEB.SHOW_DOCUMENT

    Hi I have a report in pdf format that opens ok by itself. When I use WEB.SHOW_DOCUMENT in the when_mouse_click trigger on the item in the form the report doesnt display. Only an IE window with "The page cannot be displayed" message. Here is the trigg

  • How can I use an unlocked Droid Razr M with another company's sim card?

    How do you use another company's sim card in an unlocked Droid Razr M? I tried the phone in both Global and GSM mode, but both say unknown sim card, and cannot find a network.

  • How to get information shown in taskmanager in java

    Hi, I want to have information that is shown in Task Manager of Windows for any process. When I pass process name to my API the API should return a map which will contain the following keys and values will be dynamic which will be specific for a proc

  • Tried everything but cannot get Mail to send on one account

    I know this is a wide reaching subject and I've been trawling all the web for a solution for past 48hrs and have tried everything but still cant get mail to send or connect to SMTP server for one set of accounts!!! I am running Lion on iMac and it's

  • Error -40 when attempting to import a quicktime movie

    Hello folks, I just spent a few hours altering an avi file with divx doctor so that i could get sound and import it into iMovie for burning onto dvd. IMovie attempts to import the file and it shows that the file is importing but when it's done I get