Joining a dual query to another query

dear all;
I am using the following syntax to get a particular user_place from a table which is joined to dual...see syntax below
select distinct ch.user_place from table_one inner join dual on
ch.user_place = 'TEXAS';
which give me the following results below
User_place
TEXAS
now I would like to join this result to another query that gives me the following results below.
syntax for query 2 is
select t2.population_id, t2.male, t2.female from table_zone;
results from query 2
Population Male Female
1000 60% 40%
so that my final result will be
user_place Population Male Female
TEXAS 1000 60% 40%
Hence, can this be done. if so, how can iI do it. Thank you.

user13046875 wrote:
dear all;
I am using the following syntax to get a particular user_place from a table which is joined to dual...see syntax below
select distinct ch.user_place from table_one inner join dual on
ch.user_place = 'TEXAS';
which give me the following results below
User_place
TEXASThere's no reason to use dual above; you can simply say:
select distinct
     ch.user_place
from      table_one
where     ch.user_place     = 'TEXAS'
now I would like to join this result to another query that gives me the following results below.
syntax for query 2 is
select t2.population_id, t2.male, t2.female from table_zone;
results from query 2
Population Male Female
1000 60% 40%
so that my final result will be
user_place Population Male Female
TEXAS 1000 60% 40%
Hence, can this be done. if so, how can iI do it. Thank you.Sure; just cross join the two:
select distinct
     ch.user_place
,     t2.population_id, t2.male, t2.female
from           table_one
cross join     table_zone
where     ch.user_place     = 'TEXAS'
;This will get the specific results you want in this specific case.
It may get the results you want in general, too, but I can't say for sure because I don't know what the general problem is. If you'd like help, describe what you're trying to do.

Similar Messages

  • How to make outer join in Sub Query?

    Hi!
    I'm facing one problem. Can anyone tell me - how to make outer join in sub query?
    I'm pasting one sample code -
    select e.empno, e.ename,e.job,e.sal,d.deptno,d.dname
    from d_emp e, d_dept d
    where e.deptno(+) = (
                          case
                            when d_dept.deptno = 10
                              then
                                  select deptno
                                  from d_dept
                                  where dname = 'SALES'
                          else
                            d_dept.deptno
                          end
    SQL>
    ERROR at line 15:
    ORA-01799: a column may not be outer-joined to a subqueryHow to resolve this issue?
    Regards.

    And any luck with this?
    SQL> with emp as
      2  (select 100 empno, 'Abcd' ename, 1000 sal, 10 deptno from dual
      3  union all
      4  select 101 empno, 'RRR' ename, 2000 sal, 20 deptno from dual
      5  union all
      6  select 102 empno, 'KKK' ename, 3000 sal, 30 deptno from dual
      7  union all
      8  select 103 empno, 'PPP' ename, 4000 sal, 10 deptno from dual
      9  )
    10  ,dept as
    11  (select 10 deptno, 'FINANCE' dname from dual
    12  union all
    13  select 20 deptno, 'SALES' dname from dual
    14  union all
    15  select 30 deptno, 'IT' dname from dual
    16  union all
    17  select 40 deptno, 'HR' dname from dual
    18  )
    19  select e.empno, e.ename, e.sal, d.deptno, d.dname
    20  from emp e,
    21       (select decode(a.deptno, 10, b.deptno, a.deptno) deptno, decode(a.deptno, 10, b.dname, a.dname) dname
    22      from dept a, (select deptno, dname
    23                    from dept
    24                      where dname = 'SALES'
    25                     ) b
    26       ) d
    27  where e.deptno(+) = d.deptno
    28  /
         EMPNO ENAM        SAL     DEPTNO DNAME
           101 RRR        2000         20 SALES
           101 RRR        2000         20 SALES
           102 KKK        3000         30 IT
                                       40 HR
    SQL> Cheers
    Sarma.

  • Restriction to Left Outer Joins in PS Query

    Hello I am trying to do Left Outer JOin in PS QUERY. I need to do dept tbl, job code tbl and locatable as left outer joins with JOB Table. Looks like in PS QUERY there is a error message saying as below. Can someone has any workaround to achieve this in PS QUERY. I know I can create a View and use that in PS QUERY but BUsiness Users are dependent on IT, so that doesn't work. Also, adding JOB table multiple times works but I am looking for better solution if anyone had come accorss working through PS QUERY Outer JOins.
    Windows Internet Explorer
    Left outer joins must be joined to the last record in the query. (139,290)
    OK
    Thanks,
    SC.

    Hi Mike,
    According to your description, you want to improve the performance for your DAX query in SQL Server Analysis Service Tabular model, right? Here is a white paper describes strategies and specific techniques for getting the best performance from your tabular
    models, including processing and partitioning strategies, DAX query tuning, and server tuning for specific workloads.
    http://msdn.microsoft.com/en-us/library/dn393915.aspx
    Since this is a complex DAX query, from a support perspective this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with Microsoft. Visit this link to see the various
    support options that are available to better meet your needs:
    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
    Regards,
    Charlie Liao
    TechNet Community Support

  • Joining with sub query not working

    Hi
    I am new with these complex queries. I am trying to join a sub query to a query as below;
    SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
    COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo, (SELECT EventID, SUM(Total) FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) AS Total
    FROM tblEvents AS Events1 LEFT OUTER JOIN
    tblClients ON Events1.ClientID = tblClients.ID
    WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
    GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate
    HAVING (Events1.InvoiceBatch = 5212)
    ORDER BY tblClients.Company
    I am getting these two errors;
    Msg 8120, Level 16, State 1, Line 2
    Column 'tblEvents.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Msg 116, Level 16, State 1, Line 2
    Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
    What am I missing?
    Thanks
    Regards

    SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
    COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo,Total
    FROM tblEvents AS Events1 LEFT OUTER JOIN
    tblClients ON Events1.ClientID = tblClients.ID
    LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
    ON sb.EventID = Events1.ID
    WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
    GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate,Total
    HAVING (Events1.InvoiceBatch = 5212)
    ORDER BY tblClients.Company
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page
    Says;
    Msg 4104, Level 16, State 1, Line 5
    The multi-part identifier "Events1.ID" could not be bound.
    on
    LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
    Regards

  • Outer Join with the query

    I have written the below query, our requirement is, Some employees have "Transport Allowance" but not "Project Allowance". For this, I tried to use OUTER JOIN with this query. But this query takes long time and failed. The following query works fine if the employee has both "Transport Allowance" and "Project Allowance" (without outer join) Now, I also need to retrieve the employees who have "Transport Allowance" but not "Project Allowance". How can I retrieve it?
    SELECT DISTINCT papf.employee_number
    , peev.screen_entry_value Transport_Allowance
    ,peev1.screen_entry_value Project_Allowance
    FROM apps.per_all_people_f papf
    ,apps.per_all_assignments_f paaf
    ,apps.pay_element_types_x petf
    ,apps.pay_element_types_x petf1
    ,apps.pay_element_types_x petf2
    ,apps.pay_element_entries_f peef
    ,apps.pay_element_entries_f peef1
    ,apps.pay_element_entries_f peef2
    ,apps.pay_element_entry_values_x peev
    ,apps.pay_element_entry_values_x peev1
    ,apps.pay_element_entry_values_x peev2
    ,apps.pay_input_values_x pivf
    ,apps.pay_input_values_x pivf1
    ,apps.pay_input_values_x pivf2
    WHERE
    papf.person_id = paaf.person_id
    AND paaf.assignment_id = peef.assignment_id
    AND paaf.assignment_id = peef1.assignment_id
    AND paaf.business_group_id = papf.business_group_id
    --Transport Allowance
    AND peef.element_entry_id = peev.element_entry_id
    AND petf.element_Name = 'Transport Allowance'
    AND pivf.element_type_id =petf.element_type_id
    AND pivf.name = 'Allowance'
    AND peev.input_value_id= pivf.input_value_id
    --Project Allowance
    AND peef1.element_entry_id = peev1.element_entry_id
    AND petf1.element_Name = "Project Allowance'
    AND pivf1.element_type_id = petf1.element_type_id
    AND pivf1.name = 'Allowance'
    AND peev1.input_value_id = pivf1.input_value_id
    AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
    AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
    AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
    ORDER BY papf.employee_number
    Thanks in advance.

    I am using sames tables with alias to retrieve the columns values from the same table.
    Here is my query.
    SELECT DISTINCT papf.employee_number
    , peev.screen_entry_value Transport_Allowance
    ,peev1.screen_entry_value Project_Allowance
    FROM apps.per_all_people_f papf
    ,apps.per_all_assignments_f paaf
    ,apps.pay_element_types_x petf
    ,apps.pay_element_types_x petf1
    ,apps.pay_element_entries_f peef
    ,apps.pay_element_entries_f peef1
    ,apps.pay_element_entry_values_x peev
    ,apps.pay_element_entry_values_x peev1
    ,apps.pay_input_values_x pivf
    ,apps.pay_input_values_x pivf1
    WHERE
    papf.person_id = paaf.person_id
    AND paaf.assignment_id = peef.assignment_id
    AND paaf.assignment_id = peef1.assignment_id
    AND paaf.business_group_id = papf.business_group_id
    --Transport Allowance
    AND peef.element_entry_id = peev.element_entry_id
    AND petf.element_Name = 'Transport Allowance'
    AND pivf.element_type_id =petf.element_type_id
    AND pivf.name = 'Allowance'
    AND peev.input_value_id= pivf.input_value_id
    --Project Allowance
    AND peef1.element_entry_id = peev1.element_entry_id
    AND petf1.element_Name = "Project Allowance'
    AND pivf1.element_type_id = petf1.element_type_id
    AND pivf1.name = 'Allowance'
    AND peev1.input_value_id = pivf1.input_value_id
    AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
    AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
    AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
    ORDER BY papf.employee_number
    Thanks in advance.

  • Self join using ABAP Query

    Hello all,
    How to create a self join using ABAP Query?
    Say, I have this table EKBE with belnr (materials doc num) and lfbnr (reference material doc num). I have to pick the PO's from EKBE whose belnr doesnt have any lfbnr.
    Regards
    Madhumathi A

    hi madhu,
    tables : ekbe.
    data itab like standard table of ekbe with header line.
    select * from ekbe into table itab where belnr >< 0 and lfbnr = ' '.
    loop at itab.
    write :/ itab-belnr,itab-lfbnr.
    endloop.
    check this code this works to select the orders whose belnr doesnt have any lfbnr
    reward points if useful.

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

  • To join the sql query

    Hi All
    Following query is to monitor users tablespace and temp tablesapce. How do I can join these two query as a single query. Kindly assist.
    Users tablespace mon:
    ==============
    select TT.tablespace_name,
    round(TOTAL) TOTAL,
    round(FREE) FREE,
    round(TOTAL - FREE) USED,
    round(100*(TOTAL - FREE)/TOTAL) PCT_USED
    from
    (select tablespace_name, sum(bytes)/1024/1024 FREE
    from dba_free_space group by tablespace_name) FR,
    (select tablespace_name, sum(bytes)/1024/1024 TOTAL
    from dba_data_files group by tablespace_name) TT
    where TT.tablespace_name = FR.tablespace_name(+);
    Temp tablespace mon:
    ===============
    select TT.tablespace_name,
    round(TOTAL) TOTAL,
    round(FREE) FREE,
    round(TOTAL - FREE) USED,
    round(100*(TOTAL - FREE)/TOTAL) PCT_USED
    from
    (select tablespace_name, sum(bytes_free)/1024/1024 FREE
    from v$temp_space_header group by tablespace_name) FR,
    (select tablespace_name, sum(bytes)/1024/1024 TOTAL
    from dba_temp_files group by tablespace_name) TT
    where TT.tablespace_name = FR.tablespace_name(+);

    select TT.tablespace_name,
    round(TOTAL) TOTAL,
    round(FREE) FREE,
    round(TOTAL - FREE) USED,
    round(100*(TOTAL - FREE)/TOTAL) PCT_USED
    from
    (select tablespace_name, sum(bytes)/1024/1024 FREE
    from dba_free_space group by tablespace_name) FR,
    (select tablespace_name, sum(bytes)/1024/1024 TOTAL
    from dba_data_files group by tablespace_name) TT
    where TT.tablespace_name = FR.tablespace_name(+)
    UNION
    select TT.tablespace_name,
    round(TOTAL) TOTAL,
    round(FREE) FREE,
    round(TOTAL - FREE) USED,
    round(100*(TOTAL - FREE)/TOTAL) PCT_USED
    from
    (select tablespace_name, sum(bytes_free)/1024/1024 FREE
    from v$temp_space_header group by tablespace_name) FR,
    (select tablespace_name, sum(bytes)/1024/1024 TOTAL
    from dba_temp_files group by tablespace_name) TT
    where TT.tablespace_name = FR.tablespace_name(+);

  • How to use outer join on this query?

    Hi all,
    Hope doing well,
    sir i am having one query which is here
    SELECT C.* ,
    P.Comp_Name Parent
    FROM Comp_Master C
    LEFT JOIN Comp_Master P
    ON C.Parent_ID = P.Comp_ID
    WHERE C.Comp_ID = 5;
    and here is my table Comp_Master data like this:
    Comp_ID Parent_ID Comp_Name
    5 1 abc123
    1 ROOT abc@123
    after running this query with all column value in parent column abc@123 value should come. but it's not happening.
    could u check this.
    if any query please let me know.
    Thanks

    p.s. when I run your query against your data....
    SQL> ed
    Wrote file afiedt.buf
      1  with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name from dual union all
      2                       select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name from dual
      3                      )
      4  --
      5  -- end of simulated table of test data
      6  --
      7  SELECT C.*
      8        ,P.Comp_Name Parent
      9  FROM Comp_Master C
    10       LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
    11* WHERE C.Comp_ID = 5
    SQL> /
    C PARE COMP_NA PARENT
    5 1    abc123  abc@123I get the output I expect from that query.
    So what are you expecting?
    I just ran the equivalent in SQL Server (I can't believe you got me to go and run that piece of rubbish... I haven't touched it in ages)...
    with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name union all
                         select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name
    SELECT C.*
          ,P.Comp_Name Parent
    FROM Comp_Master C
         LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
    WHERE C.Comp_ID = 5... and it gave me the same output.

  • Join in a query

    Hello!
    I'm neawby in SQL, and I have some problems with a query...
    I have a table called "Artist" like this:
    ART_ID     ART_NAME         ART_DESCRIPTION
    1          Artist1          Desc1
    2          Artist2          Desc2
    3          Artist3          Desc3
    4          Artist4          Desc4And another table called "Tour" like this:
    TOUR_ID   TOUR_DATE          TOUR_ART_ID
    1         10/10/2013         1
    2         14/07/2014         4And definitively, I want to show something like this:
    ART_ID     ART_NAME         ART_DESCRIPTION         TOUR_DATE
    1          Artist1          Desc1                   10/10/2013
    2          Artist2          Desc2
    3          Artist3          Desc3
    4          Artist4          Desc4                   14/07/2014If no tour_date for this artist, I want to show the artist too.
    Thanks in advance!

    John Stegeman wrote:
    Marccccc,
    Let me give you a hint to see if it will help you. Try it out, and if you cannot get it, come back and tell us what you tried
    Hint: outer joins.
    Edit: Blu ruined my nifty little idea :)Apologies John. I was in a kind mood as the OP at least bothered to display his data using {noformat}{noformat} tags so we could read it, and made it clear what he wanted, unlike some of the "I've got this... +unformatted data+ and I want this... +unformatted output+" questions we get.  ;)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • IN A NATURAL JOIN THE ANSWER QUERY DEPENDS OF PROJECTION ??!!

    Hi,
    Related to this question
    Link: problems with natural join
    Does the answer query depend of projection in a complex NATURAL JOIN query?
    Thanks,
    Ion

    You are most likely encountering this bug:
    Bug 5031632 - Wrong results from NATURAL JOIN, Metalink Note: 5031632.8
    It currently affects all versions of Oracle.
    You can tell something weird is going on by the EXPLAIN PLAN results:
    Query:
    SELECT     *
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3878360587
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  1 |  HASH JOIN       |      |     1 |    39 |    28   (8)| 00:00:01 |
    |*  2 |   HASH JOIN      |      |     1 |    29 |    17   (6)| 00:00:01 |
    |*  3 |    HASH JOIN     |      |     1 |    23 |     9  (12)| 00:00:01 |
    |   4 |     VIEW         |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL   |      |       |       |            |          |
    |   6 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER     |      |       |       |            |          |
    |   8 |        FAST DUAL |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW         |      |     3 |    45 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL   |      |       |       |            |          |
    |  11 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL  |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    VIEW          |      |     4 |    24 |     8   (0)| 00:00:01 |
    |  15 |     UNION-ALL    |      |       |       |            |          |
    |  16 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  17 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |      FAST DUAL   |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |   VIEW           |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  21 |    UNION-ALL     |      |       |       |            |          |
    |  22 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  23 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  24 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       2 - access("AUTHORSHIP"."IDAUTHOR"="AUTHOR"."IDAUTHOR")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    Query:
    SELECT     NAMEBOOK
    FROM     BOOK
    NATURAL JOIN
         AUTHORSHIP
         NATURAL JOIN
              AUTHOR
              NATURAL JOIN
              COUNTRY
    WHERE     COUNTRY.NAMECOUNTRY = 'Canada'
    Explain Plan:
    SQL> /
    PLAN_TABLE_OUTPUT
    Plan hash value: 3246924444
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     1 |    24 |    27   (4)| 00:00:01 |
    |*  1 |  HASH JOIN            |      |     1 |    24 |    27   (4)| 00:00:01 |
    |   2 |   MERGE JOIN CARTESIAN|      |     1 |    21 |    19   (6)| 00:00:01 |
    |*  3 |    HASH JOIN          |      |     1 |    11 |     9  (12)| 00:00:01 |
    |   4 |     VIEW              |      |     2 |    16 |     2   (0)| 00:00:01 |
    |   5 |      UNION-ALL        |      |       |       |            |          |
    |   6 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |       FILTER          |      |       |       |            |          |
    |   8 |        FAST DUAL      |      |     1 |       |     2   (0)| 00:00:01 |
    |   9 |     VIEW              |      |     3 |     9 |     6   (0)| 00:00:01 |
    |  10 |      UNION-ALL        |      |       |       |            |          |
    |  11 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  12 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  13 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  14 |    BUFFER SORT        |      |     5 |    50 |    19   (6)| 00:00:01 |
    |  15 |     VIEW              |      |     5 |    50 |    10   (0)| 00:00:01 |
    |  16 |      UNION-ALL        |      |       |       |            |          |
    |  17 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  18 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  19 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  20 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  21 |       FAST DUAL       |      |     1 |       |     2   (0)| 00:00:01 |
    |  22 |   VIEW                |      |     4 |    12 |     8   (0)| 00:00:01 |
    |  23 |    UNION-ALL          |      |       |       |            |          |
    |  24 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  25 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  26 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    |  27 |     FAST DUAL         |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("BOOK"."IDBOOK"="AUTHORSHIP"."IDBOOK")
       3 - access("AUTHOR"."IDCOUNTRY"="COUNTRY"."IDCOUNTRY")
       7 - filter(NULL IS NOT NULL)
    41 rows selected.There are two major differences in these plans.
    1. The correct result has HASH JOINS. However the incorrect result has a MERGE JOIN CARTESIAN. A cartesian join should not be here as there is no need for one per the table structure and NATURAL JOIN syntax.
    2. There is a filter condition missing in the predicate information session.
    Both #1 and #2 above point to the bug I identified. The current work around us to use the JOIN ... ON syntax.
    HTH!

  • Different Between In and Join Function of Query

    Hi Team,
    I have confuse for the below query getting different count.
    Version DB :-
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Query:-1
    Getting Count :-3917
    SELECT COUNT (*)
      FROM stg_ser_level_inv_db a, map_stg_gsm_serv b
    WHERE a.account_number_v IN (SELECT account_number_v
                                    FROM map_transaction_number MAP
                                   WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.trans_num_v
                        IN (SELECT trans_num_v
                              FROM map_transaction_number MAP
                             WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.trans_type_v
                         IN (SELECT trans_type_v
                               FROM map_transaction_number MAP
                              WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.acct_no = b.stg_account_number
       AND a.serv_account_number_v= b.stg_serv_link_code
       AND NOT EXISTS (
              SELECT 1
                FROM cb_sub_ar_ap ar
               WHERE ar.account_link_code_n = b.ab_serv_acc_link_code
                 AND ar.bill_cleared_flg_v = 'N'
                 AND ar.trans_num_v IN (SELECT target_trans_num_v
                                          FROM map_transaction_number MAP
                                         WHERE MAP.trans_type_v IN ('F', '4')))--3917why when u IN condition and join condition count is different. please let me know why?
    Thanks for advance ...
    Second :-2 Join Condition
    Total Count :-789948
    select COUNT(*)
        FROM STG_SER_LEVEL_INV_DB A , MAP_STG_GSM_SERV B,MAP_TRANSACTION_NUMBER ARAP_CUR
    WHERE  A.ACCOUNT_NUMBER_V = ARAP_CUR.ACCOUNT_NUMBER_V
    AND A.TRANS_NUM_V  = ARAP_CUR.TRANS_NUM_V
    AND A.TRANS_TYPE_V = ARAP_CUR.TRANS_TYPE_V
    AND A.ACCT_NO = B.STG_ACCOUNT_NUMBER
    and a.SERV_ACCOUNT_NUMBER_V  = B.STG_SERV_LINK_CODE
    and ARAP_CUR.TRANS_TYPE_V in ('F','4')
    and not exists (select 1 from CB_SUB_AR_AP ar
          where ar.account_link_code_n = B.AB_SERV_ACC_LINK_CODE
          and AR.BILL_CLEARED_FLG_V = 'N'
          and ar.trans_num_v = ARAP_CUR.TARGET_TRANS_NUM_V);---789948

    Hi,
    Whenever you have a problem, please post a complete test script that people can run to re-create the problem and test their ideas. Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data. In this case, data that produced no more than 10 rows of output for each query should be plenty.
    Simplify the problem as much as possible. For example, it looks like both your queries are joining tables a and b the same way. Why not pretend that you have only 1 table, ab, that is the same as the result set of joining a and b? Post CREATE TABLE and INSERT statements for the relevant columns of ab.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    There are several differences between those two queries.
    For one thing, Query 1 is doing a 2-way join between a and b, and then filtering that result set by comparing it to another table (let's call it map). So if a contains 5 rows and b contains 2 rows, the result set will contain at most 5 * 2 = 10 rows. Perhaps only 8 of those 10 rows will have matching rows in map. Note that the number of rows in map, or how many rows in map match rows in a or b doesn't matter. Query 2, on the other hand, is doing a 3-way join of a, b and map, so if map has 100 rows, the result set could have as many as
    (5 * 2) * 100 = 1000 rows. We know that it won't have that many rows, because only 8 out the rows from the a-b join have matching rows in map, but the result set of the 3-way join could still have as many as
    (8) * 100 = 800 rows.
    Since you didn't post test versions of your tables, I'll use tables from the scott schema to illustrate. Scott.dept has 4 rows, only 3 of which match rows in scott.emp, so
    SELECT  d.*
    FROM     scott.dept  d     -- tables a and b in your query play this role
    WHERE     d.deptno  IN (
                      SELECT  e.deptno
                   FROM     scott.emp  e     -- map plays this role in your query
    ;produces 3 rows of output. Exactly how many rows are in emp (that number happens to be 14) and how many of those rows match rows in dept (that happens to be 14, also) doesn't matter; all that matters in the query above is that 3 of the rows in dept have matches. However, the fact that 14 of the rows in emp have matches is important in the query bleow:
    SELECT     d.*
    FROM     scott.dept  d
    JOIN     scott.emp   e  ON  d.deptno  = e.deptno
    ;which produces 14 rows of output.
    Another differece is that Query 1 says that there are 3 conditions that relate table a to map; a given row in a will be included in the result set if any row in map meets condition 1, any row in map meets condition 2, and any row in map meets condition 3. It doesn';t matter if you have to look at 2 or 3 rows in map to meet all those conditions. Query 2 says that a row from a will be included only if there is a single row in map that meets all 3 conditions.

  • Replace joins with normal query

    hi experts ,
    can u help me out splving in this issue.
    i want to convert this query in to normal query I.e  with out usin gany joins .pls help me out.
    select a~ebeln
            b~ebelp
            b~loekz
            a~bukrs
            a~wkurs
            a~lifnr
            a~ekorg
            a~ekgrp
            a~waers
            a~bedat
            b~txz01
            b~menge
            b~meins
            b~netpr
            b~elikz
            b~erekz
            b~wepos
            b~weunb
            b~repos
            b~webre
            b~matkl
            c~eindt
       from ekko as a
       inner join ekpo as b
       on aebeln eq bebeln
    inner join eket as c
    on  bebeln eq cebeln
    and bebelp eq cebelp
    into corresponding fields of table t_ekko_ekpo
    where a~bukrs in s_bukrs
      and lifnr   in s_lifnr
      and ekorg   in s_ekorg
      and ekgrp   in s_ekgrp
      and a~bedat in s_bedat.
      and c~eindt in s_eindt.
    Thanks in advance ,

    Hi all,
    Can someone tell me if it is possible to replace a
    call like
    <jbo:ShowValue datasource="dsNews"
    dataitem="NisStory" /> with
    String s = jbo.ShowValue(dsNews,NisStory)? Or if there
    is another way to get the output of the tag into a
    String?One way to do it would be to wrap the execution of <jbo:ShowValue/> with a body tag that captures its body and writes it to a variable in the pageContext. The usage would be something like:
    <mytaglib:capture var="aString">
    <jbo:ShowValue/>
    </mytaglib:capture>
    the capture tag handler would take the body content in the doAfterBody callback and expose it as "aString" in the pageContext attributes.
    >
    Thanks in advance.
    Regards BasBr - J

  • Self Joining and Inline Query. A tricky report.

    I am stuck with a very tricky situation.Please help.This is PROD issue.
    I have written a SQL code which has 1 inline queries,and displays the right results
    with the right report output
    Dont get confused.Just go thru this.
    select   pie.id_inst_code,
             ISNULL(PN.Active, 0)                 'Active',
    from position_master_input_event pie,
    (select  insx.id_inst_xref_type,insx.id_inst_xref,count(*) 'PrimaryListing'
    from instrument ins, instrument_xref insx
    where ins.id_inst = insx.id_inst
    and   insx.flg_active = 'Y'
    and   ins.flg_active  = 'Y'
    group by insx.id_inst_xref_type,insx.id_inst_xref
    )PN
    where     id_entity = 'AGL'
    and       pie.id_inst_code *= PN.id_inst_xref
    and       pie.id_src_inst_code_type*= PN.id_inst_xref_type
    group by  pie.id_inst_code,PN.Active,
    Table :Instrument_xref
    id_inst      id_inst_xref_type    id_inst_xref  flg_active
    0372285      SE                   B0DV8Y9       Y
    0372285      IS                   GB00B03MLX29  Y
    Table :Instrument
    id_inst      id_inst_xref_type    id_inst_xref  flg_active  flg_primary_listing
    0372285      SE                   B0DV8Y9       Y           N 
    OUTPUT:
    id_inst_xref                      Active
    B0DV8Y9                           1
    PERFECT.Works fine
    2) Now comes the tricky part.:
        0372285 also has GB00B03MLX29 which has flg_active to Y and which also maps to 0372285.
        Am I right?
        New reportOutput
        id_inst_xref                      Active   PRIMARY ISIN
        B0DV8Y9                           1        1
        So,now I want a SELF JOIN this way built into the code:
        (hardcoded values work)
        (i)
        select  a.id_inst_xref
        from instrument_xref a,
             instrument_xref b
        where b.id_inst_xref ='B0DV8Y9'
        and   b.id_inst = a.id_inst
        and   b.id_inst_xref_type in ('SE','IS')
        and   a.id_inst_xref =  'GB00B03MLX29'
        (ii)
         select count(*) 'PrimaryISIN'
         from instrument ins,
             instrument_xref insx
         where ins.id_inst = insx.id_inst
         and   insx.flg_active = 'Y'
         and   ins.flg_primary_listing = 'Y'
         and   ins.flg_active = 'Y'
         And now LINKING ALL :
        select   pie.id_inst_code,
             ISNULL(PN.Active, 0)                 'Active',
        from position_master_input_event pie,
        (select  insx.id_inst_xref_type,insx.id_inst_xref,count(*) 'PrimaryListing'
         from instrument ins, instrument_xref insx
         where ins.id_inst = insx.id_inst
         and   insx.flg_active = 'Y'
         and   ins.flg_active  = 'Y'
         group by insx.id_inst_xref_type,insx.id_inst_xref
        )PN,
        (select count(*) 'PrimaryISIN'
         from instrument ins,
             instrument_xref insx
         where ins.id_inst = insx.id_inst
         and   insx.flg_active = 'Y'
         and   ins.flg_primary_listing = 'Y'
         and   ins.flg_active = 'Y'
          and     insx.id_inst_xref = ( 
                                           select  DISTINCT  a.id_inst_xref
                                            from    instrument_xref a,
                                            instrument_xref  b
                                      where b.id_inst_xref = 'B0DV8Y9'
                                          and     b.id_inst = a.id_inst
                                          and     b.id_inst_xref_type in ('SE','IS')
                                       and    a.id_inst_xref =  'GB00B03MLX29'
        where     id_entity = 'AGL'
        and       pie.id_inst_code *= PN.id_inst_xref
        and       pie.id_src_inst_code_type*= PN.id_inst_xref_type
        group by  pie.id_inst_code,PN.Active,
        THE Self join works fine as long as it is hardcoded.
        But assume there can br multiple such situations as the above,and I dont want to
        hardcode the values,how can I build the NEW REPORT by SELF JOINING.
        Please can someome help.This is a tricky one.
        Is there a better way to this

    Isn't this the same question as:
    Passing values dynamically Froman 'INLINE Query' to a 'SUB QUERY'
    and
    Another query regarding Inline Query and Self Join and pass Column Values

  • Problem with JOINs in SELECT query

    The parameter  wa_dob-e_dob is not getting its definition ....
    it contains DOB in current yr.
    As i am using Joins also Workarea.... so is it coz Joins & WA cant be used simultaneously in a SELECT query....
    Is there any other option to do the same...?
    *  Global Structure
    TYPES : BEGIN OF t_data ,                     "Structure
            emp_dob TYPE pa0002-gbdat,
            emp_Mailid TYPE pa0105-usrid,
           END OF t_data,
           BEGIN OF t_dob,
           e_dob TYPE pa0002-gbdat,
           e_pernr type pa0002-pernr,
           END OF t_dob.
    *  Global Internal Tables (I_)
    DATA : i_data TYPE TABLE OF t_data,           "Internal Table for output data
           i_dob TYPE TABLE OF t_dob.             "Internal table for Dob
    *  Global Work Area (WA_)
    DATA : wa_data TYPE  t_data,                  "Work Area for output data
           wa_dob TYPE  t_dob.                    "Work Area for Dob
    *this is the query where i am getting error
    * Field "WA_DOB-E_DOB" Not found.
    LOOP AT i_dob INTO wa_dob.
        SELECT pa0002~gbdat pa0105~usrid INTO CORRESPONDING FIELDS OF wa_data
          FROM pa0002
          INNER JOIN pa0105
          ON pa0002~pernr = pa0105~pernr
          WHERE  pa0105~subty EQ 'MAIL' AND
         wa_dob-e_dob BETWEEN w_sysdate AND w_edit_sysdate.
        ENDSELECT.
        APPEND wa_data TO i_data.
        CLEAR wa_data.
        CLEAR wa_dob.
        CLEAR l_temp_dob.
      ENDLOOP.

    Hi,
    you are checking the work area in the SELECT. IN WHERE condition of the select u should specify fields in either of the tables pa0002 , pa0105 for data population.
    The select is on the database table and not on the work area.for checking the data in the work area do this way:
    loop at it_dob into wa_dob.
    if wa_dob-e_dob between the range u want (w_sysdate AND w_edit_sysdate)
    endif.
    endloop.
    ie: wa_dob-e_dob >w_sysdate AND wa_dob-e_dob < w_edit_sysdate or
        wa_dob-e_dob < w_sysdate AND wa_dob-e_dob  >  w_edit_sysdate
    watever ur requirement is..
    regards,
    madhu

Maybe you are looking for

  • Search and Delete a specific record from a CSV file

    Hi All, I am new to java . I want to search for the records from CSV file and delete the row form the file. Below is my Sample .csv 100||a100||1b100 200||b200||dc300 200||bg430||ef850 400||f344||ce888 Now I need some help in below requirements. 1.How

  • UWL: Jump another role when clicking in a WI (Task)

    HI Experts! I tell them that I've have a problem when working with the UWL for SAP Enterprise Portal modules and SRM7.0 7.13. The stage on which I locate the problem is this, we have created many custom roles portal with many features (standard and o

  • Pass parameters to a report

    Hi all, I would like to know how to pass parameters to a report to filter the data from an external application, for example a Oracle ADF app. Thanks, Jhon BI PUB 11.1.1.7

  • Send all messages in Drafts Mailbox in Mail - How to do this in Automator?

    A MacUser only for 20 years, I've just moved from Eudora eMail to Apple's Mail program. One feature that I would like to have with Mail that I had with Eudora is the ability to "queue" a message (similar to putting the message into the DRAFTS mailbox

  • Test plan

    Hi friends, Please any one tell me, what are steps involved in test plan preparation in bw