Many to Many Relationchip joining issues

I have the following 3 tables and I need to join it to get the data in a specific format.
Below is the sample data for sample tables.
Table1:
ID         exp    req_date      Time        crit_met
3308    Yes    3/31/2015    00:00.0    Yes
Table2:
ID        cont_co                con_dept     first_name    middle_init    last_name   
suffix
3308                        
3308    Company_Test    Dept_Test    Test              Previous3      Mr
3308    Company_Test    Dept_Test    Test              Previous2      Mr
3308    Test_Comp         Test_Dpt       Test              Tester    
Table3:
ID       gna_id    gna_dor_id    cont_co                  con_dept       
first_name       last_name
3308    991        45                   Company_Test        Dept_Test      
Test1               Tester
3308    991        46                   Test_Comp             
Test_Dpt         Test2               Tester
I need to do a join on the above 3 tables on ID and get the data in the below format. This is just a sample output. I do have more than 6 tables on which I need to do a join.
Is there anyway that we can get the data in this format or can we use SSRS ????
<---------Table 1--------><--------------------- Table 2 --------------------------><----------Table 3------------->
ID       exp    req_date        cont_co                first_name    last_name    gna_dor_id  
    cont_co
3308    Yes    3/31/2015                                                                           
45                  Company_Test
                                          Company_Test    
  Test             Previous3       46                  Test_Comp
                                          Company_Test      
Test             Previous2        
                                          Test_Comp            
Test             Tester   

Please try this:
DECLARE @T1 TABLE ( id INT, [exp] NVARCHAR(3))
INSERT @T1
( id, [exp] )
VALUES ( 3308, N'yes' );
DECLARE @T2 TABLE ( id INT, cont_co NVARCHAR(100), last_name NVARCHAR(20))
INSERT @T2
( id, cont_co, last_name )
VALUES ( 3308, N'', N'' ) ,
( 3308, N'Company_Test', N'Previous3' ) ,
( 3308, N'Company_Test', N'Previous2' ) ,
( 3308, N'Test_Comp', N'Tester ' )
DECLARE @T3 TABLE ( id INT , gna_dor_id INT , cont_co NVARCHAR(100))
INSERT @T3
( id, gna_dor_id, cont_co )
VALUES ( 3308, 45, N'Company_Test' ) ,
( 3308, 46, N'Test_Comp' );
;WITH s1 AS (
SELECT a.id ,
a.exp ,
b.cont_co ,
b.last_name , ROW_NUMBER() OVER (ORDER BY a.id ) AS rn
FROM @T1 AS a
LEFT JOIN @T2 AS b ON a.id = b.id
), s2 AS (
SELECT x.id ,
x.exp ,
y.gna_dor_id ,
y.cont_co , ROW_NUMBER() OVER (ORDER BY x.id ) AS rn
FROM @T1 AS x
JOIN @T3 AS y ON y.id = x.id
SELECT *
FROM s1
full JOIN s2 ON s2.rn = s1.rn AND s2.id = s1.id;

Similar Messages

  • Many-to-many performance issue

    I realize that many-to-many joins have been discussed before (yes, I looked through many threads), but I'm having a slight variation on the issue. Our data warehouse has been functioning for a couple of years now, but we're now experiencing a dramatic degradation in report performance. I'll tell you everything I know and what I've tried. My hope is that someone will have an idea that hasn't occurred to me yet.
    The troubling data links deal with accounts and account_types. Each transaction will have one account, but each account can have multiple account_types and each account_type is made up of multiple accounts. It ends up looking like this:
    Transaction_cube --< account_dimension >--< account_type_table
    Given the many-to-many relationship between account and account_type, this is the only architecture I could come up with that will maintain data integrity in the transaction cube.
    I know that this is the cause of the performance issues because the reports run normally when this is removed. The volume of data obviously increases over time, but the problem appeared very suddenly -- not a gradual degradation that one would expect from a volume issue. The cube is partitioned by year and we're a little below last year's growth.
    The other fact to throw in is that the account_type table did increase in size by an additional 30% when we first noticed the problem. However, the business was able to go back and remove half of the account_types (unused types) so now the table has fewer rows than it had before we noticed the problem (~15k rows in the account_type table).
    We have tried pinning the table so that it remain in memory, but that did not help. I tried creating a materialized view combining accounts and account_types with a similar lack of improvement. I've tried adding indexes, but there is still a full-table scan. All database objects are analyzed nightly after the data load is completed.
    I'm fresh out of ideas at this point. Any suggestions and/or ideas would be greatly appreciated.

    I've thought about that. What it would mean would be aprox. 20 additional columns for each of the different account_types. Unfortunately, that would also mean that all the reports that use the account_type would have to have a condition:
    WHERE acct_type1='Income Stmt." OR acct_type2='Income Stmt." OR ....
    Since the account_types are not set up in a hierarchy and there must be only one row for account, I'm not sure that this is a feasible solution.
    Thank you for the suggestion.

  • OLAP issue with MANY TO MANY mapping

    Hi All,
    We have a requirement where we have to pull specific measures & associated dimensions data from an OLAP to SQL tables. The source cube has almost 80 % of MANY TO MANY mappings.
    When we pull this data to SQL tables either by writing MDX or DMX dimension level metric values are not matching with what OLAP browsing is providing.
    When we pull this measure with only regular dimensions metric values with all dimensions exactly match. The mismatch issue comes when we have at least 1 MANY TO MANY dimension part of MDX or DMX query. Further to this we have pulled all intermediate facts
    & dimensions involved in MANY TO MANY mapping into SQL tables & tried a number of JOINS but the metric values haven’t match up.
    We are very close on delivery dates & are not sure on any resolution. Could you please guide us on next steps here.
    Thanks is advance.

    Hi All,
    We have a requirement where we have to pull specific measures & associated dimensions data from an OLAP to SQL tables. The source cube has almost 80 % of MANY TO MANY mappings.
    When we pull this data to SQL tables either by writing MDX or DMX dimension level metric values are not matching with what OLAP browsing is providing.
    When we pull this measure with only regular dimensions metric values with all dimensions exactly match. The mismatch issue comes when we have at least 1 MANY TO MANY dimension part of MDX or DMX query. Further to this we have pulled all intermediate facts
    & dimensions involved in MANY TO MANY mapping into SQL tables & tried a number of JOINS but the metric values haven’t match up.
    We are very close on delivery dates & are not sure on any resolution. Could you please guide us on next steps here.
    Thanks is advance.

  • Toplink - Many-to-Many Mapping issue

    Hi
    I have the following tables
    User
    Place
    Team
    User : uid , name (where uid is primay key)
    Place : uid , pid( where uid and pid are composite primary keys)
    Team : tid , name , pid( where tid is primary key)
    Here the following mappings :
    one user is belongs to many places
    one user have many teams( by place)
    user have many teams
    i have created many to many mapping between place(or user) and team tables using intermediate table user_team( uid ,tid). But when i try to retrieve the teams for user id then i m getting all the teams. Here i need to filter the teams by only place id instead getting all the teams.
    For example:
    if user id is belongs to place id 101 then i need to get only teams belongs to place id 101. But i m getting all the places(101,102) teams for same user id which belongs to place id 101.
    Please help me out how i can create valide mapping between all the tables to retrieve valid data. i m using toplink workbench(10g - 9.0.4).

    Your model seems confused, you may wish to re-think you model. It seems odd that a place would have a user id, seems more like it is a m-m join table between user and team, but then it should have a team id not a place id.
    You can use a selectionCriteria() on a ManyToManyMapping to define complicated m-m joins, but you would probably be better re-thinking your model. What object model are you trying to do exactly? Go from there, then define your data-model.
    -- James : http://www.eclipselink.org

  • JOIN for many-to-many linked tables?

    I have two tables, A and C, linked by a many-to-many intersection table B.
    I'd like to do a select from A with a LEFT OUTER JOIN to C for items mapped via B. A row in A may or may not have rows in C linked to it.
    I've tried to do a select using sub-selects but then I don't get the rows from A that don't have related rows in C.
    When I try to use the syntax of a LEFT OUTER JOIN I can't figure out how to link A and C via the B table.
    I would appreciate suggestions for how to approach this.
    Thanks in advance,
    George

    EXAMPLE
    SQL> L
      1  with A as (
      2  select 1 col1, 1 col2 from dual union all
      3  select 2     , 1     from dual union all
      4  select 3     , 2     from dual)
      5  ,
      6  B as (
      7  select 1 col2, 1 col3 from dual union all
      8  select 2     , 3     from dual)
      9  ,
    10  C as  (
    11  select 1 col3 from dual union all
    12  select 2      from dual union all
    13  select 3      from dual
    14  )
    15  select *
    16  from      A
    17  LEFT JOIN B ON (A.COL2=B.COL2)
    18* LEFT JOIN C ON (B.COL3=C.COL3)
    SQL> /
          COL1       COL2       COL2       COL3       COL3
             1          1          1          1          1
             2          1          1          1          1
             3          2          2          3          3

  • TS4051 This MacBook Pro (circa 2011) is the second Apple laptop with the same issue.  When I change sites (or at least many of them), the Mac issues a single chime.  I do not have any clue what this might be ... or if it even needs repairing if I can stan

    This MacBook Pro (circa 2011) is the second Apple laptop I have owned with the exact same issue.  When I change sites (or at least many of them), the Mac issues a single chime.  I do not have any clue what this might be ... or if it even needs repairing if I can stand the chime.
    If anyone has any ideas, I surely would love to hear!  Many thanks!
    Madelaine

    This is the Mac Pro (desktop workstation) forum.  You will probably get more meaningful results here:
    MacBook Pro: Notebooks: Apple Support Communities
    good luck

  • Limiting a many to many join

    Hello,
    I__m wondering if there is a way to limit a many to many join by a specific
    value in a column in the join table. I have a join table that has the two
    foreign key fields which are the ids to the tables and another column that
    I want to limit on. So the SQL would be something like below but I want
    to do it through ejb3. Any idea how this can be accomplished?
    Select phone.number, __ from company, company_phone, phone where
    company_phone.primay = __Y__ and company.id = company_phone.company_id and
    phone.id = company_phone.phone_id and company.id = __1234__;
    If so does it work for the other relationships (one to many and many to
    one)?
    Thanks,
    Craig

    Kodo does have support for limiting a join based on a constant value; we
    call them "constant joins". See the following documentation, and let us
    know if you have any questions:
    http://solarmetric.com/Software/Documentation/4.0.0EA/docs/full/html/ref_guide_mapping_notes_nonstdjoins.html

  • One-to-Many implemented with a join Table

    Hello,
    Is it possible to implement a One-to-Many relationship with a join table, just like
    the Reference Implementation does.
    Regards,
    Jeroen

    "Jeroen Ferdinandus" <[email protected]> wrote in
    news:[email protected]:
    Is it possible to implement a One-to-Many relationship with a join
    table, just like the Reference Implementation does.Not with our CMP, you will have to resort to BMP for that.
    Cedric

  • Many to Many Retrieval Issue

    While understanding the limitation of having both a child and parent both be updatable, I am having trouble getting the child (read only mapping) to retrieve the appropriate objects??? is there some trick to get this to happen? the writable mapping is able to retrieve them, but the read only one just doesn't populate?
    Thanks,
    Michael

    Ok, I think I am closer to the real issue... your example provides a fremework that functions as it should.
    However, what I am doing is:
    (FYI: My parents can update their children in the M-M mapping)
    1. Copying a child object using a copy constructor.
    The constructor retains all existing relationships to it's parent and children (both many to many) by looping through them and calling the setParent and setChild appropriate methods that you recommended.
    ...this works properly
    2. Then I assign a new (already persisted) Parent object to the newly created child. When I persist the child, I get the following error after fully validating the uow:
    Exception occured: LOCAL EXCEPTION STACK:
    EXCEPTION [TOPLINK-7056] (TopLink - 9.0.3.2 (Build 429)): oracle.toplink.exceptions.ValidationException
    EXCEPTION DESCRIPTION: The wrong object was registered into the UnitOfWork. The object [com.wachovia.retail.dal.business.loanreview.Element@9815354] should be the object from the parent cache
    Can you explain why this is happening?
    FYI, if I attempt to assign a new (already persisted) child, it works fine.

  • Many to many join table with different column names

    Hi have a joint table with different column names as foreign keys in the joining
    tables...
    e.g. i have a many to many reltnshp btwn Table A and Table B ..and join table
    C
    both have a column called pk.
    and the join table C has columns call fk1 and fk2
    does cmd require the same column name in the join table as in the joining table?
    are there any workarounds?
    thanks

    HI,
    No, the foreign key column names in the join table do not have to match the primary
    key names in the joined tables.
    -thorick

  • How to resolve many-to-many join by 2 one-to-many joins

    Hi,
       I was asked many times how to resolve many to many relationship between two tables. I read to use 2 one -to- many relationships to resolve this. Can some expalin me when many to many relationship occurs between two tables and how to reslove them with practicle examples. Is there any article on this?
    Regards,
    Nanda Kishore

    Hi,
    Please check below link.
    http://www.forumtopics.com/busobj/viewtopic.php?p=859029&sid=20d79e3df07b0d8b41aadfbd902bb6b2
    http://blog.oaktonsoftware.com/2011/04/bridge-tables-and-many-to-many.html
    Thanks,
    Amit

  • Mapping issue, "many to many"  mapping

    Hi specialists!
    I have to map this structure:
    source
    segment_1   (1...n)
    key_1
    aaa
    bbb
    segment_2   (1...n)
    key_2
    ccc
    ddd
    Target:
    segment_2
    ccc
    ddd
    The condition is segment_1=>key1 = segment_2=>key2
    The problem is that I need to check each segment_1 with each segment_2.
    Is it possible using standard mapping functions?

    Dani_K,
    This can be done with standard mapping if your source.segment_1.key_1 is unique.   If it is not, you could end up with a many to many mapping which would be difficult no matter how you map. 
    Try this:
    For segment_2
    source.segment_1.key_1 (right click, context, source) ---> sort --->
    source.segment_2.key_2 (right click, context, source) ---> sort --->
    equalsS --->   ifWithoutElse --->
    source.segment_2  (then)               
    removeContexts  (after the If Then)--->   target.segment_2
    For ccc
    source.segment_1.key_1 (right click, context, source) ---> sort --->
    source.segment_2.key_2 (right click, context, source) ---> sort --->
    equalsS --->   ifWithoutElse --->
    source.segment_1.ccc  (right click, context, source)     (then)               
    removeContexts  (after the If Then)--->  SplitByValue(Each Value) ---> target.segment_2.ccc
    For ddd
    source.segment_1.key_1 (right click, context, source) ---> sort --->
    source.segment_2.key_2 (right click, context, source) ---> sort --->
    equalsS --->   ifWithoutElse --->
    source.segment_1.ddd (right click, context, source)     (then)               
    removeContexts  (after the If Then)--->   SplitByValue(Each Value) ---> target.segment_2.ddd
    Ideally, the segment_1.Key_1 and segment_2.key_2 are sorted before you process the message.  If so, remove the sort above.

  • Many to many join

    Hello,
    Please help me create the many-to-many relationship between these tables that I willl need to do a Master Detail form. The master is tblStandardSheets (PK: ID) the detail is tblSubject (PK: SUBJECTID) and the link is tblLink (PK: RECID, FK: ID, SUBJECTID).
    CREATE TABLE "tblStandardSheets"
    (     "ID" NUMBER NOT NULL ENABLE,
         "SHEET" VARCHAR2(100),
         "TITLE" VARCHAR2(255),
         CONSTRAINT "tblStandardSheets_PK" PRIMARY KEY ("ID") ENABLE
    CREATE OR REPLACE TRIGGER "BI_tblStandardSheets"
    before insert on "tblStandardSheets"
    for each row
    begin
    if :NEW."ID" is null then
    select "TBLSTANDARDSHEETS_SEQ".nextval into :NEW."ID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblStandardSheets" ENABLE
    CREATE TABLE "tblLink"
    (     "ID" NUMBER NOT NULL ENABLE,
         "RECID" NUMBER NOT NULL ENABLE,
         "SUBJECTID" NUMBER NOT NULL ENABLE,
         CONSTRAINT "tblLink_PK" PRIMARY KEY ("RECID") ENABLE
    ALTER TABLE "tblLink" ADD CONSTRAINT "TBLLINK_FK" FOREIGN KEY ("ID")
         REFERENCES "tblStandardSheets" ("ID") ON DELETE CASCADE ENABLE
    ALTER TABLE "tblLink" ADD CONSTRAINT "TBLLINK_FK2" FOREIGN KEY ("SUBJECTID")
         REFERENCES "tblSubject" ("SUBJECTID") ON DELETE CASCADE ENABLE
    CREATE OR REPLACE TRIGGER "BI_tblLink"
    before insert on "tblLink"
    for each row
    begin
    if :NEW."RECID" is null then
    select "TBLLINK_SEQ".nextval into :NEW."RECID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblLink" ENABLE
    CREATE TABLE "tblSubject"
    (     "SUBJECTID" NUMBER NOT NULL ENABLE,
         "SUBJECT" VARCHAR2(255),
         CONSTRAINT "tblSubject_PK" PRIMARY KEY ("SUBJECTID") ENABLE
    CREATE OR REPLACE TRIGGER "BI_tblSubject"
    before insert on "tblSubject"
    for each row
    begin
    if :NEW."SUBJECTID" is null then
    select "TBLSUBJECT_SEQ".nextval into :NEW."SUBJECTID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblSubject" ENABLE
    ALTER TABLE "tblSubject" ADD CONSTRAINT "tblSubject_FK" FOREIGN KEY ("SUBJECTID")
         REFERENCES "tblLink" ("SUBJECTID") ON DELETE CASCADE ENABLE
    ORA-02270: no matching unique or primary key for this column-list
    Edited by: user6753348 on Mar 31, 2009 1:39 PM

    Like this:
      CREATE TABLE "tblStandardSheets"
       (     "ID" NUMBER NOT NULL ENABLE,
         "SHEET" VARCHAR2(100 BYTE),
         "TITLE" VARCHAR2(255 BYTE),
          CONSTRAINT "tblStandardSheets_PK" PRIMARY KEY ("ID")
    CREATE OR REPLACE TRIGGER "BI_tblStandardSheets"
    before insert on "tblStandardSheets"
    for each row
    begin
    if :NEW."ID" is null then
    select "TBLSTANDARDSHEETS_SEQ".nextval into :NEW."ID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblStandardSheets" ENABLE
      CREATE TABLE "tblSubject"
       (     "SUBJECTID" NUMBER NOT NULL ENABLE,
         "SUBJECT" VARCHAR2(255 BYTE),
          CONSTRAINT "tblSubject_PK" PRIMARY KEY ("SUBJECTID")
    CREATE OR REPLACE TRIGGER "BI_tblSubject"
    before insert on "tblSubject"
    for each row
    begin
    if :NEW."SUBJECTID" is null then
    select "TBLSUBJECT_SEQ".nextval into :NEW."SUBJECTID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblSubject" ENABLE
      CREATE TABLE "HR"."tblLink"
       (     "ID" NUMBER NOT NULL ENABLE,
         "RECID" NUMBER NOT NULL ENABLE,
         "SUBJECTID" NUMBER NOT NULL ENABLE,
          CONSTRAINT "tblLink_PK" PRIMARY KEY ("RECID")
          CONSTRAINT "TBLLINK_FK" FOREIGN KEY ("ID")
           REFERENCES "tblStandardSheets" ("ID") ON DELETE CASCADE ENABLE,
          CONSTRAINT "TBLLINK_FK2" FOREIGN KEY ("SUBJECTID")
           REFERENCES "tblSubject" ("SUBJECTID") ON DELETE CASCADE ENABLE
    CREATE OR REPLACE TRIGGER "BI_tblLink"
    before insert on "tblLink"
    for each row
    begin
    if :NEW."RECID" is null then
    select "TBLLINK_SEQ".nextval into :NEW."RECID" from dual;
    end if;
    end;
    ALTER TRIGGER "BI_tblLink" ENABLE
    /You have to create the sequences yourself...
    HTH
    Roel

  • Insert/delete many to many join in 9.0.3

    Can anyone tell me a good way to create/delete an intersection row in a many to many relationship? I can do it programmatically in the client, but I'd rather have the middle tier view object or application module handle the code. Currently I'm creating a JClient application but later I will be putting the application in a browser. I don't want to rewrite the code every time I change my client application.
    Thanks

    I forgot to mention that I'm using the BC4J framework.
    Mike

  • Many to many relationship issue

    Guys,
         How do we deal with the situation where we have many to many relationship between 2 different characteristics?
    Thanks,
    RG

    Hi,
    I assume you are talking about data modeling.
    When you are required to decide how to model two Char with many to many relations
    1. If you keep them in Same Dimension table the size of the dimension table will be more.
    lets say 100 Customers & 100 Materials
    Now if you keep them in same dimension..
    lets say C1 will have combination of M1 till M100.similarly for other customers
    So Total rows in dimension table will be 100x 100 = 10000!!!
    It will again be of comparable size to fact table and not recommended.
    2.You always try to define them in different dimensions
    Now ,You try keeping them in diffrent dimension..in this case Customer dimension will have only 100 rows & Mateial dimension will have only 100 Rows.very small when compared to fact table size.
    Hope this helps
    Sriman

Maybe you are looking for

  • DVD Studio Pro Crashes when trying to import file

    Hey all, Hope you can help me because this is driving me crazy! Whenever I try to import .ac3/.m2v files to DVDSP, the program crashes. The strange thing is that it is happening only when I try it on one particular file. I seem to be able to import a

  • Which CPS Version for NW7.31?

    Dear experts, We are running CPS build M33.10-45085 on NW7.1 We are preparing an upgrade to NW7.31 Now, I really cannot find information on which version of CPS I should run. Should we upgrade CPS? Will CPS build M33.10-45085 run with NW7.31? to whic

  • M1217mfw with readiris device not installing correctly

    I run Win7/64 bit.  M1217nfw device.  trying to download Readiris.  It downloaded (4 times actually) and each time hangs on setting the scanner.   I tried reinstalling my printer (don't have the CD, but downloaded and installed M1210 series printer s

  • Itunes says memory on ipod is full but is actually empty

    Hi, I hope someone can help me with this: I recently downloaded itunes 7 as recommended for my Ipod Nano 2nd generation, my ipod is showing, but when i try to sync my library with my ipod it tells me there is not enough space to do this, the memory b

  • Is new OSX 10.9.5 upgrade a problem?

    Safari 7.1 update broken, cannot use the browser  This thread just posted in communities" Safari" has me concerned!    #1 Should I be?  #2  Has anyone experienced this? #3 Should I wait a while till doing osx upgrade and Safari update?