Joining four tables

hi
i have four tables, given the sample data for the relevant field of the tables here under
table company:
company_id     comp_parent_org_id
241     238
457     279
225     200
478     200
10     279
table representative:
rep_id     rep_parent_org_id
238     234
279     170
200     234
table mobile_unit     :     
rep_id     company_id     msisdn     creation_date
238     241     91944400000     1-Sep-08
279     457     91944400005     1-Sep-07
200     225     91944400010     10-Sep-08
200     478     91944400100     5-Jul-08
279     10     91944410100     5-Jul-08
table organization     :
organization_id     name
234     chennai
170     kerala
238     al
279     da
200     sd
now i want to join all these table to get the output as below
table output required: between creation_date in table mobile_unit
name     no of companies     no of msisdns
chennai     3     3
kerala     2     2
the organization table contains the name for all the ids in the table company, representative, etc
name field should reflect the name of the distinct rep_parent_org_id
companies column should count the number of company_id in company table w.r.t comp_parent_org_id (same as rep_id in representative table) which in turn should lie under the rep_parent_org_id
for example here rep_parent_org_id 170 , its name is kerala, then under this id we have got 279 as the rep_id (same as comp_parent_org_id). with 279 as comp_parent_org_id we have got two company_id so no of companies =2
no of msisdns column
rep_parent_org_id 170 , its name is kerala, then under this id we have got 279 as the rep_id. for this 279 rep_id , we have got two msisdn (i.e 91944400005 & 91944410100) so count is 2
i tried in this way as per the answer for my previous question, but am not able to count companies
select DISTINCT o.name, count(mu.msisdn)
FROM RTMS.ORGANIZATION O
INNER JOIN RTMS.REPRESENTATIVE R
     ON O.ORGANIZATION_ID=R.PARENT_ORG_ID
INNER JOIN RTMS.MOBILE_UNIT MU
     ON R.REP_ID=MU.REP_ID
GROUP BY O.NAME
can anybody help me out
thanks
Aemunathan
Edited by: Aemunathan on Sep 10, 2008 11:15 PM

Hi,
Good question! Clear question, carefully written, complete sample data (but not too much), nothing irrelevant, clear sample output.
Would you like to make your questions even better? Enclose the code and data in code tags, as described in the FAQ, to preserve spacing.
You have a one-to-many relationship between representative and mobile_unit, so when you join those two tables, you can multiply rows in representative. For example, there are two rows in mobile_unit with rep_id = 279, so when you join mobile_unit to representative, it looks like there were two rows from representative with rep_id = 279. In the three-table query you posted, that was okay.
You also have a one-to-many relationship between representative and company. If you simply join company the way you joined mobile_unit, those "extra" rows in representative become a problem. For example, there are two rows in company with comp_parent_rep_id = 279. If, because of the join with mobile unit, there seem to be two rows from represnetative with rep_id = 279, then both of the rows from comany will join to both of the rows from representative.
To solve that problem, you should do the join between representative and mobile_unit separately from the join between representative and company. Here's one way to do that:
WITH     m     AS
(     -- Begin sub-query m, counts from mobil_unit
     SELECT     rep_parent_org_id
     ,     COUNT (msisdn)     AS msisdn_cnt
     FROM     representative     r
     JOIN     mobile_unit     mu     ON r.rep_id     = mu.rep_id
     GROUP BY     rep_parent_org_id
)     -- End sub-query m, counts from mobil_unit
,     c     AS
(     -- Begin sub-query c, counts from company
     SELECT     rep_parent_org_id
     ,     COUNT (company_id)     AS company_cnt
     FROM     representative     r
     JOIN     company          c     ON r.rep_id     = c.comp_parent_org_id
     GROUP BY     rep_parent_org_id
)     -- End sub-query c, counts from company
SELECT     o.name
,     m.msisdn_cnt
,     c.company_cnt
FROM     organization     o
JOIN               m     ON o.organization_id     = m.rep_parent_org_id
JOIN               c     ON o.organization_id     = c.rep_parent_org_id
;If there is a chance that some organiztion will have matching rows in mobile_unit but not in company (or vice-versa), then you should make the joins in the main query outer joins.

Similar Messages

  • How to join four tables in Update query??

    Please how to join four tables in a single query to update one table row??

    You can use this syntax to update. Here updation of 1 column to a constant value (50) in multiple rows in Table A based on an associated 'SOURCE' value in table B
    Table A joins to Table B based on the TableA.definition_id = TableB.Att_Def_id
    like..
    update TableA
    set value =50
    where
    TableA.definition_id = TableB.Att_Def_id
    and TABLEB.Source = 'NEWPRODUCT'

  • Inner join on four tables

    hi all,
    i am facing the problem with the inner join in the select query for 4 tables.
    can i use the inner join for tables in SAP 6.0 version,
    it is going to dump.
    here is my code
    SELECT DISTINCT apernr abegda aendda awagetype aamount acurrency
            altrctry brufnm banred bvorna bnachn cgroupcode d~vdsk1
    FROM pa9011 AS a INNER JOIN pa0002 AS b ON bpernr = apernr
                      INNER JOIN pa9013 AS c ON cpernr = bpernr
                      inner join pa0001 as d on dpernr = cpernr
                      INTO CORRESPONDING FIELDS OF TABLE it_bonus
    WHERE a~pernr IN s_pernr AND
           a~begda IN s_date AND
           a~subty EQ s_subty AND
           a~wagetype EQ wa_perbonus AND
           a~ltrctry = gc_ind AND
           a~amount > 0 AND
           b~endda = '99991231' AND
           c~groupcode IN s_loc AND
           c~endda = '99991231' and
           d~endda = '99991231'
        ORDER BY a~pernr.

    hi this is the dump ,
    In a SELECT access, the read file could not be placed in the target
    field provided.
    Either the conversion is not supported for the type of the target field,
    the target field is too small to include the value, or the data does not
    have the format required for the target field.

  • Adding one more table to the select statement joining 4 tables gives dump

    Hi All,
    There is a select statement using which four tables namely VBAK,VBAP,LIPS and LIKPUK(view) are joined(inner join).Here, date and time fields are selected from LIPS and used.
    My requirement is to consider the Date (LIKP - WADAT_IST) instead of LIPS-ERDAT  and time(LIKP-SPE_WAUHR_IST) is to be used instead of LIPS-erzet.
    Neither LIPS nor LIKPUK contains time(SPE_WAUHR_IST) field. And, I cannot remove LIPS table or LIKPUK view as each contains a unique field which is used in the report.
    When I tried to join LIPS in the select query, it is going to dump.
    Can someone suggest a good approach ?
    Thanks,
    Pavan

    Thank you for the detailed explanation of the dump.
    The dump details together with your code lead to the answer: 42.
    Regards,
    Clemens

  • SQL Joins & joining 4 tables help.

    Post Author: n8than1
    CA Forum: Data Connectivity and SQL
    Hello,  I'm trying to build a report to show orders shipped, and pull in costing information from my sales tables.  I have 4 tables I'm using data from, and I'm linking my shipping master and shipping items tables by a left outer join on shipper number.  I'm linking my sales master table and sales item table using a left outer join on sales order number.  Now I need to link the 4 tables together, and everything I try spits out duplicate line items. I'm linking my shipping master table to sales order master using a inner join on sales order number. here is a copy of my query: SELECT "sorels"."fmatlcost", "sorels"."fsetupcost", "sorels"."flabcost", "sorels"."fovhdcost", "sorels"."forderqty", "shmast"."fshipdate", "shitem"."fshipqty", "shitem"."fpartno", "somast"."fusercode", "shmast"."fcbcompany" FROM   (("<SQL Database>"."dbo"."somast" "somast" INNER JOIN "<SQL Database>"."dbo"."shmast" "shmast" ON "somast"."fsono"="shmast"."fcsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."sorels" "sorels" ON "somast"."fsono"="sorels"."fsono") LEFT OUTER JOIN "<SQL Database>"."dbo"."shitem" "shitem" ON "shmast"."fshipno"="shitem"."fshipno" WHERE  ("shmast"."fshipdate">={ts '2007-11-01 00:00:00'} AND "shmast"."fshipdate"<{ts '2007-11-30 00:00:01'}) AND "shitem"."fpartno" NOT  LIKE 'PM%' ORDER BY "somast"."fusercode", "shmast"."fcbcompany"

    Post Author: GraemeG
    CA Forum: Data Connectivity and SQL
    At a glance, the problem seems to be primarily that you are not giving enopugh information to your joins to limit the data displayed. If you added an order and shipment line number to the joins this may help. Just for fun, can you put the table structures here and I'll give it a whirl? Alternatively, email me a sample from all four tables and I'll put something together and send it back. Use graemeg AT falum DOT co DOT nz.
    Cheers G

  • Could not able to join physical tables in obiee using a dataconversion func

    Hi,
    i am trying to join physical tables wc_perf_ratings_d and w_wrkfc_evt_month_f with condition as
    "Oracle Data Warehouse"."Catalog"."dbo"."Dim_WC_PERF_RATINGS_D"."RATING_CD" = to_char(round( "Oracle Data Warehouse"."Catalog"."dbo"."Fact_W_WRKFC_EVT_MONTH_F"."ORIG_PERF_RATING",2)). But i am getting the below syntax error while applying this.
    [nQSError:27002] Near <(>: Syntax error [nQSError:26012]
    i used the same condition on database and i got results.
    select rating_cd,
    to_char(round(orig_perf_rating,2)) as orig_perf_rating,
    headcount,
    fte,
    salary_annl,
    total_service_days
    from wc_perf_ratings_d, w_wrkfc_evt_month_f
    where wc_perf_ratings_d. rating_cd= to_char(round(w_wrkfc_evt_month_f.orig_perf_rating,2));
    Here i am trying to convert the format of ORIG_PERF_RATING field and trying to join with RATING_CD in physical layer.
    so my question is, is it possible to join in obiee using such conditions? i do not want to convert the field format in ETL and i wanted to do that at obiee level. Could anybody please suggest how to do it?

    Hi,
    Thanks for the link. i was trying another method in joining the two fields (rating_cd, orig_perf_rating) at database level. As i said both these fields are of varchar datatype. Earlier i tried to convert orig_perf_rating field from number to string. But i want to convert string data in (rating_cd) to number. so i have values in it like (1,2,3,4,bep, ep, vp, nr). Actually i have a requirement to create a database view for the dimension table (wc_perf_ratings_d) having rating_cd field with new datatype (number) instead of string and then join this field with orig_perf_rating in fact table which already has numbers. Along with the number rating fields, there are four particular string fields in rating_cd (bep, ep, vp, nr) as i mentioned. so while converting, i also have to convert these specific string fields in to partcular numbers. (bep=1, ep=5, nr=0, vp=3). Now, all this requirement is at database level as i am creating a db view. so my question is how to apply the to_number conversion function for converting the rating_cd field values (bep, ep, vp, nr) from string to specific mentioned numbers. Could you please help?
    for eg: create or replace view as select to_number(rating_cd....................
    Thank you.

  • Linking four Tables

    HI!
       How can I get the data from all these four tables..The table names and fields are as follows :
    MARA -Matnr
    MARA-Attyp
    MALG-Matnr
    MALG-Lmod
    EINA-Matnr
    EINA-Lnfnr
    EINA-Anum
    EINE-Lnfnr
    EINE-Org
    The selection criteria is Lnfnr. Anybody can help me? Thank in advance....
    Regards,
    Nathan

    Hi, 
       Check this sample code
    ELECT-OPTIONS:
          s_matnr FOR mara-matnr,
          s_werks FOR ekpo-werks,
          s_lifnr FOR ekko-lifnr OBLIGATORY,
          s_ekorg FOR ekko-ekorg OBLIGATORY,
          s_ekgrp FOR ekko-ekgrp OBLIGATORY,
          s_bedat FOR ekko-bedat OBLIGATORY,
          s_ebeeln FOR ekko-ebeln ,
          s_ebelp FOR ekpo-ebelp .
    >START OF SELECTION
    START-OF-SELECTION.
      SELECT  ekkoebeln  ekpoebelp  ekpomatnr  maktmaktx  ekpo~werks
              ekpomenge  ekponetpr  ekko~lifnr
              INTO CORRESPONDING FIELDS OF TABLE t_itab
              FROM ( ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln ) INNER
              JOIN makt ON maktmatnr = ekpomatnr  WHERE
       ekpo~matnr IN s_matnr AND
       ekpo~werks IN s_werks AND
       ekko~lifnr IN s_lifnr AND
       ekko~ekorg IN s_ekorg AND
       ekko~ekgrp IN s_ekgrp AND
       ekko~bedat IN s_bedat AND
       ekko~ebeln IN s_ebeeln AND
       ekpo~ebelp IN s_ebelp .
      "selects the output data from ekko,ekpo and makt tables and stores in
      "t_itab
       Use Inner join for the four tables....
    Reward if useful

  • Query joing Four tables

    Hi,
    I've four tables as below:
    SQL> desc per_absence_attendances
    Name                                      Null?    Type
    ABSENCE_ATTENDANCE_ID                     NOT NULL NUMBER(10)
    BUSINESS_GROUP_ID                         NOT NULL NUMBER(15)
    ABSENCE_ATTENDANCE_TYPE_ID                NOT NULL NUMBER(9)
    ABS_ATTENDANCE_REASON_ID                           NUMBER(9)
    PERSON_ID                                 NOT NULL NUMBER(10)
    AUTHORISING_PERSON_ID                              NUMBER(10)
    REPLACEMENT_PERSON_ID                              NUMBER(10)
    PERIOD_OF_INCAPACITY_ID                            NUMBER(9)
    ABSENCE_DAYS                                       NUMBER(9,4)
    SQL> desc per_absence_attendance_types
    Name                                      Null?    Type
    ABSENCE_ATTENDANCE_TYPE_ID                NOT NULL NUMBER(9)
    BUSINESS_GROUP_ID                                  NUMBER(15)
    INPUT_VALUE_ID                                     NUMBER(9)
    DATE_EFFECTIVE                            NOT NULL DATE
    NAME                                      NOT NULL VARCHAR2(30)
    ABSENCE_CATEGORY                                   VARCHAR2(30)
    SQL> desc per_all_people_f
    Name                                      Null?    Type
    PERSON_ID                                 NOT NULL NUMBER(10)
    EFFECTIVE_START_DATE                      NOT NULL DATE
    EFFECTIVE_END_DATE                        NOT NULL DATE
    BUSINESS_GROUP_ID                         NOT NULL NUMBER(15)
    PERSON_TYPE_ID                            NOT NULL NUMBER(15)
    FULL_NAME                                          VARCHAR2(240)
    SQL> desc Per_all_assignments_f
    Name                                      Null?    Type
    ASSIGNMENT_ID                             NOT NULL NUMBER(10)
    PERSON_ID                                 NOT NULL NUMBER(10)
    SUPERVISOR_ASSIGNMENT_ID                           NUMBER(15)The tables are related as below:
    i). per_all_people_f contains information about employee, like person_id, full names
    ii). per_absence_attendances contains information for leave records for employees. This table is joined to per_all_people_f using the column PERSON_ID
    iii). per_absence_attendance_types contains information about types of absences (e.g Annual Leave). Joined to per_absence_attendances on column ABSENCE_ATTENDANCE_TYPE_ID
    iv). Per_all_assignments_f contains information about employee assignment (supervisor etc). Is joined to per_all_people_f using the column PERSON_ID. The coulmn SUPERVISOR_ASSIGNMENT_ID contains the person_id for the supervisor of this employee.
    I would like to use SUPERVISOR_ASSIGNMENT_ID to get the Full name of the supervisor for this employee. Ultimately, I'm looking for an output like this:
    FULL_NAME  ABSENCE_TYPE  ABSENCE_DAYS APPROVED_BY
    XXXXX         Annual Leave       5                         yyyyWhere yyyy is the full name for the supervisor of employee xxxx. Anyone with a hint on this?
    Regards
    dula
    Edited by: user13005731 on Jul 1, 2012 10:27 PM

    may be
    select p.full_name, supervisor.full_name as supervisor_full_name
      from per_all_people_f             p,
           per_absence_attendances      aa,
           per_absence_attendance_types t,
           per_all_assignments_f        a,
           per_all_people_f             supervisor
    where p.person_id = aa.person_id(+)
       and aa.absence_attendance_type_id = t.absence_attendance_type_id(+)
       and p.person_id = a.person_id
       and sysdate between p.effective_start_date and p.effective_end_date
       and supervisor.person_id = a.supervisor_assignment_id

  • Joining bridge tables

    Hi,
    I have two bridge tables, bridge1, bridge2.
    Bridge1 has a customer-id which is also in fact table, so joined the bridge1 to fact table
    Bridge2 has a product-id which is also in fact table, so joined the bridge2 to fact table.
    bridge 1, bridge2 has contact-id key, but that key doesnot exist in fact table.
    So, here there are four tables, fact, bridge1,bridge2, contact table.
    I joined the tables in RPD as,
    bridge1--->Fact----->Brdige2
    bridge1---->Contact---->Bridge2
    According to my requirement, in bridge2 table, I have created a new logical column(Name) ,and written a case statement, case when facttable.customer active=N then
    contact.name.
    In report I pulled the Name column created in bridge2 and a measure column from fact table.---(I got wrong result, I should get 30,000, but got 55,000),Checked the sql generated by BI Server.
    In sql, it is also joined to bridge1 table, and thats the reason I got 55,000.
    Please help/suggest me, how to resolve this.
    All the help is highly appreciated.
    Thanks
    SR

    Based on your description can you try this option?
    Physical layer joins:
    bridge1--->Fact----->Brdige2
    Contact---->Bridge2
    BMM:
    Pull these tables in bmm
    bridge1--->Fact----->Brdige2
    For logical table Brdige2->Source->Properties->Add Contact table
    and then create a Name logical column as said.
    Create dimension hierarchies for both bridge1,Brdige2 and set the content level
    Let me know updates

  • How to join these tables?

    hi,
    i was asked to create a view with select fields in these four tables. but i'm having a hard-time with the joins.
    oe_order_headers
    wsh_delivery_details
    ra_customers
    ra_addresses
    can someone help.
    thanks
    allen

    Allen Try this
    --Execute this first
    begin
    fnd_client_info.set_org_context(204); --R11
    mo_global.set_policy_context('S',204); --R12
    end;
    Run this sql..
    select * from oe_order_headers_all a, oe_ship_to_orgs_v b,wsh_delivery_details d
    where a.ship_to_org_id=b.organization_id
    and a.header_id=d.source_header_id;
    Thanks
    Nagamohan

  • JOIN question... Join two tables without omiting rows

    I ran into a problem that should have an easy solution (I hope), but I'm having a hard time coming up with a solution.
    Basically, I have two tables, one with actual amounts and one with the budget. I am to write a sql select statement that joins these tables together and includes all of their rows. I've been able to join the tables together using JOIN, LEFT JOIN, and RIGHT JOIN, but it always omits rows that I need.
    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity sake, I've built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables aren't quite as simple, but I didn't think it was relavent for this question.
    AMOUNT_TABLE
    FISCAL_YEAR
    PERIOD
    ACCT_UNIT
    ACCOUNT
    SUB_ACCOUNT
    AMOUNT
    2013
    1
    11111
    555555
    0000
    100
    2013
    1
    11111
    555555
    1000
    100
    2013
    1
    11111
    555555
    2000
    100
    2013
    1
    11111
    555555
    3000
    100
    2013
    1
    11111
    555555
    4000
    100
    BUDGET_TABLE
    FISCAL_YEAR
    PERIOD
    ACCT_UNIT
    ACCOUNT
    SUB_ACCOUNT
    BUDGET
    2013
    1
    11111
    555555
    3000
    200
    2013
    1
    11111
    555555
    4000
    200
    2013
    1
    11111
    555555
    5000
    200
    2013
    1
    11111
    555555
    6000
    200
    Here is the output I'm hoping for. Notice that SUB_ACCOUNTs 0000, 1000, and 2000 show amounts with no budget since there isn't a matching row in the BUDGET_TABLE. And likewise, for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amounts since there isn't a matching row in the AMOUNT_TABLE.
    (output)
    FISCAL_YEAR
    PERIOD
    ACCT_UNIT
    ACCOUNT
    SUB_ACCOUNT
    AMOUNT
    BUDGET
    2013
    1
    11111
    555555
    0000
    100
    0
    2013
    1
    11111
    555555
    1000
    100
    0
    2013
    1
    11111
    555555
    2000
    100
    0
    2013
    1
    11111
    555555
    3000
    100
    200
    2013
    1
    11111
    555555
    4000
    100
    200
    2013
    1
    11111
    555555
    5000
    0
    200
    2013
    1
    11111
    555555
    6000
    0
    200
    Hopefully, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use ANSI join syntax - FULL OUTER JOIN:
    with amount_table as (
                          select 2013 fiscal_year,1 period,11111 acct_unit,555555 account,0000 sub_account,100 amount from dual union all
                          select 2013,1,11111,555555,1000,100 from dual union all
                          select 2013,1,11111,555555,2000,100 from dual union all
                          select 2013,1,11111,555555,3000,100 from dual union all
                          select 2013,1,11111,555555,4000,100 from dual
         budget_table as (
                          select 2013 fiscal_year,1 period,11111 acct_unit,555555 account,3000 sub_account,200 budget from dual union all
                          select 2013,1,11111,555555,4000,200 from dual union all
                          select 2013,1,11111,555555,5000,200 from dual union all
                          select 2013,1,11111,555555,6000,200 from dual
    select  nvl(a.fiscal_year,b.fiscal_year) fiscal_year,
            nvl(a.period,b.period) period,
            nvl(a.acct_unit,b.acct_unit) acct_unit,
            nvl(a.account,b.account) account,
            nvl(a.sub_account,b.sub_account) sub_account,
            nvl(a.amount,0) amount,
            nvl(b.budget,0) budget
      from      amount_table a
            full join
                budget_table b
              on (
                      a.fiscal_year = b.fiscal_year
                  and
                      a.period = b.period
                  and
                      a.acct_unit = b.acct_unit
                  and
                      a.account = b.account
                  and
                      a.sub_account = b.sub_account
    FISCAL_YEAR     PERIOD  ACCT_UNIT    ACCOUNT SUB_ACCOUNT     AMOUNT     BUDGET
           2013          1      11111     555555           0        100          0
           2013          1      11111     555555        1000        100          0
           2013          1      11111     555555        2000        100          0
           2013          1      11111     555555        3000        100        200
           2013          1      11111     555555        4000        100        200
           2013          1      11111     555555        6000          0        200
           2013          1      11111     555555        5000          0        200
    7 rows selected.
    SQL>
    SY.

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Joining 18 tables -- one at a time or in two stages ?? best one..??

    I have to join 18 tables,.. Is it best to join all 18 in a single shot or to go with
    multi stages-- 9 tables in one stage and after that anotther 9 tables..
    Please anyone give me a good suggestion on this with some reason...
    Thanks in advance

    If you can look at your query and recognise that it is trying to collect (say) two small result sets and then join the result sets, then it is actually a good idea to express the query in that fashion to Oracle.
    Take for example a query that sums last week's profits for a supermarket by department using a 9 table query in about 2 minutes. A similar query reports the previous week's profits with a marginally different query in about two minutes. You write the two queries as inline views and join them to report the percentage change in profit by department - and the query takes 4 hours because Oracle has used "complex view merging" to turn your two 9-table queries into a single 18-table query.
    In this case, a workaround is to use the /*+ no_merge */ hint. In outline, something like:
    select     {columns}
    from
         select /*+ no_merge */
              dept_no,
              etc.
         from     ...
         )     lw,
         select /*+ no_merge */
              dept_no,
              etc.
         from     ...
         )     pw
    where
         pw.dept_no = lw.dept_no
    ;In less obvious cases you may still be able to find that you can break up a big query into a few smaller, logical sections, and use this technique to generate and join what are, in effect, intermediate results.
    An alternative to the /*+ no_merge */ hint is to use subquery factoring to the same end. There's a more complex example of the method here: http://jonathanlewis.wordpress.com/2007/07/01/internet-sql/
    In either case, avoid turning your 18-table query into 18 separate pieces and sticking them back together - it may make the optimizer do some very silly things. Karen Morton mentions an example of this on her blog: http://karenmorton.blogspot.com/2008/06/dont-do-work-you-dont-have-to-do.html
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "The greatest enemy of knowledge is not ignorance,
    it is the illusion of knowledge." (Stephen Hawking)

  • Using a view to join two tables

    Thank you in advance for any advice you can lend.
    I am using this code in my MySQL db to create a view.
    select
        job.id as job_id,
        umr_cost_calculation.plant_name,
        max(umr_cost_calculation.id) as max_id
    from
        job,
        umr_cost_calculation
    where
        job.id = umr_cost_calculation.job_id
    group by job.id , umr_cost_calculation.plant_name
    I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
    1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
    2) If I leave the max_id on the report, will this force the view to always update?

    Try:
    Select
    D1.EmpLoginID,
    Count(D1.ID),
    Count(D1.AlarmCode),
    D1.EmpName,
    D1.EmpAddress,
    D2.Db2Count
    FROM DB1.Data D1
    LEFT JOIN (SELECT
    empLoginID, Count(*) as Db2Count
    FROM DB2.ALL_Database
    WHERE site = 'Atlanta'
    GROUP BY empLoginID
    ) D2
    ON D1.EmpLoginID = D2.EmpLoginID
    GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
    Order BY D1.empLoginID ASC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Help needed in using Pivot by joining 2 tables

    Hello everyone,
    I am very new to usage of Pivot that includes joining 2 tables. Below is the scenario and request your help in this regard.
    Table1
    ID1  Description
    1     Stationary
    2     Apparel
    3     Home Decor
    Note : ID1 is unique
    Table2
    ID2     ID1       Item
    1         1          Book
    2         1          Paper-A4
    3         2          T-Shirt
    4         1          Pencil
    5         3          Flower Vase
    Note : ID2 is unique
    I am trying to get the below result set.
    ID2 Stationary   Apparel   Home Decor
    1     Book          NULL         NULL
    2     Paper-A4    NULL         NULL
    3     NULL          T-Shirt      NULL
    4     Pencil         NULL         NULL
    5     NULL          NULL         Flower Vase
    Please help in this regard.
    Thanks in advance,
    Kiran

    Just guessing
    SELECT id2,
    CASE WHEN Description='Stationary'
    THEN Item  END [Stationary],
    CASE WHEN Description='Apparel'
    THEN Item  END [Apparel],
    CASE WHEN Description='Home
    Decor' THEN Item  END [ Home
    Decor]
    FROM t1 JOIN t2 ON t1.id1=t2.id1
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for

  • How to find out Shopping Cart created in backend system or ECC system

    Hi All, I am new  to SAP SRM7.0.  The Client has implemented "Extended Classic Scenario".  i.e. SC>Approval>PO>Confirmation>Invoice process in ECC. We created few SC with "Free text" i.e. Describe what you need option in SC. The SC is created with 4

  • Errors while performing non-Unicode database export

    Hi, I am exporting of a non-unicode database (to perform a unicode conversion). The export has completed without any problems, but I frequently got the following messages in logfile. Error 1- UMGCOMCHAR read check skip, no data found; probably old SP

  • Build and Deployment Tools

    Hi All, Are there automated build and deployment tools available? are there any recommendations? Thanks Sravz

  • Xception when pasing french chars in xml for websrvce deplyd in weblogi 8.1

    Hi All, I am using weblogic 8.1 and trying to pass French characters in the xml (encoding="UTF-8") for the webservice. I am getting the following exception when executing the webservice.core.rpc.StubImpl._invoke method. java.io.CharConversionExceptio

  • Status Flag -can someone please help

    Hi My report results shows me logon_status. I would like the values for this status displayed as following. If value is WRONG PW - I would like report to display this value in Red. If the value is OK then in Green. Can this be done in htmldb?? many t