Conditional Join

I ahve 2 tables:
Table A
COL X
123
345
567
789
Table B
COL Y                COL Z
ALL                    Tom
789                     HarryOutput I want is: If the user is Tom then I want all the values from Table A and if the user is Harry I want just the matching value from Table A (789)
Thanks in advance

I like that solution; neater than mine and includes NULL's if there are any present in col_x:
with tab1 as (select 123 col_x from dual union all
              select 345 col_x from dual union all
              select 567 col_x from dual union all
              select 789 col_x from dual union all
              select null col_x from dual),
     tab2 as (select 'ALL' col_y, 'Tom' col_z from dual union all
              select '789' col_y, 'Harry' col_z from dual)
select t1.col_x, t2.col_z
from   tab1 t1,
       tab2 t2
where  decode(t2.col_y, 'ALL', 1, t2.col_y) = decode(t2.col_y, 'ALL', 1, t1.col_x)
     COL_X COL_Z
       123 Tom 
       345 Tom 
       567 Tom 
       789 Tom 
           Tom 
       789 HarryEdited by: Boneist on 13-Mar-2009 13:59
Bizarre; that shows up in the shaded code box in the preview text, but not when posted. Despite the presence of the requisite tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Question about a conditional join

    Is it possible to do a conditional join based on a field in a table?
    say I have the query below and the table fields ate the bottom. I am trying to get the exact syntax for doing a conditional join. Can any one help?
    Thanks
    select e.fname,e.lname,a.areaname
    FROM employee e
    JOIN area a ON (If e.newareaid is not null and date being searched for >= e.movedate then a.areaid = e.newareaid ELSE a.areaid = e.areaid
    ======================================================
    For example
    Employee table
    empid
    areaid
    fname
    lname
    newareaid
    movedate
    Area table
    areaid
    areaname

    Hi,
    In this particular case, the complicated join condition can be simplified considerably.
    There are 2 situations that have different join conditions, but in each situation a.areaid has to match something (let's call it join_id) from the employee table, and that can be determined just by looking at the row in the employee table. If we decide what join_id is before starting the join, then the join condition will be quite simple:
    WITH     got_join_id
         SELECT     fname, lname, areaid, newareaid
         ,     CASE
                  WHEN  newareaid              IS NOT NULL
                  AND       date_being_searched_for   >= movedate
                      THEN  newareaid
                   ELSE  areaid
              END     AS join_id
         FROM     employee
    SELECT  e.fname, e.lname, a.areaname
    FROM      got_join_id  e
    JOIN      area           a   ON  a.areaid = e.join_id
    ;You could also skip the sub-query, and put the CASE expression in the join condition:
    SELECT  e.fname, e.lname, a.areaname
    FROM      got_join_id  e
    JOIN      area           a   ON  a.areaid = CASE
                                 WHEN  newareaid              IS NOT NULL
                                     AND       date_being_searched_for   >= movedate
                                        THEN  newareaid
                                  ELSE  areaid
                             END
    ;This is basically what Hoek did, except Hoek complicated it by putting the comparison to a.areaid inside the CASE expression.
    Edited by: Frank Kulash on Apr 15, 2013 3:22 PM

  • ViewObject : Conditional Join Option in ADF

    Hi,
    I have a viewObject A and B which are connect by viewLinks from 1 to * relationship. So it is certain that whenever i make a call to this view Object it will have join operation also been called. But my requirement or test is to have something that does conditional join when required. For example i have a search form with a checkBox that is for weather to include the join or exclude the join. and result is shown in the table below according to whether a checkbox in search form was checked or not.
    => I came up with Dynamic SQL query which might solve my test case but i am wondering if there is best adf ways to do that... Also i am concern about performance since i will be dealing with huge data.
    Thanks
    jdev :11.1.1.3.0
    Edited by: 896719 on Jan 9, 2013 12:47 PM

    Hi
    Excuse me,My English isn't very good.
    you can set bind variable through EL, you should add Depno from Dept VO to the page binding and then set it to the bind variable
    but After you choose Deptno you should run the second View Obj(Emp VO) through bean.
    Habib

  • Dynamic WHERE or conditional JOIN?

    I have a 3 table join that I need to filter in either of two ways depending on row data. Initially I had the following select statement:
    SELECT Warnings.WarningID, Subscriptions.UserID, Accounts.AccountName, Accounts.Ask, Warnings.Direction, Warnings.Rate, Warnings.Active
    FROM Warnings INNER JOIN
    Subscriptions ON Warnings.SubscriptionID = Subscriptions.SubscriptionID INNER JOIN
    Accounts ON Subscriptions.AccountID = Accounts.AccountID
    WHERE (Warnings.Active = 1)
    My problem is to filter this further. Warnings.Direction is a bit where 0 means '<' and 1 means '>' and is meant to be used to differentiate between 'Accounts.Ask > Warnings.Rate' and 'Accounts.Ask < Warnings.Rate' so that I can select whatever
    is relevant for each row.
    I went through a series of failed attempts focusing on the WHERE clause, but then I tried the Design Query Editor and it produced a condition JOIN instead. The closest I've come so far is this is this:
    SELECT Warnings.WarningID, Subscriptions.UserID, Accounts.AccountName, Accounts.Ask, Warnings.Direction, Warnings.Rate, Warnings.Active
    FROM Warnings INNER JOIN
    Subscriptions ON Warnings.SubscriptionID = Subscriptions.SubscriptionID INNER JOIN
    Accounts ON Subscriptions.AccountID = Accounts.AccountID AND Accounts.Ask < Warnings.Rate
    WHERE (Warnings.Active = 1)
    which at least filters correctly for '<'. Is it possible to update this maybe with a CASE statement so that the conditional JOIN can tackle either Warnings.Direction option? Something along the lines of:
    SELECT Warnings.WarningID, Subscriptions.UserID, Accounts.AccountName, Accounts.Ask, Warnings.Direction, Warnings.Rate, Warnings.Active
    FROM Warnings INNER JOIN
    Subscriptions ON Warnings.SubscriptionID = Subscriptions.SubscriptionID INNER JOIN
    Accounts ON Subscriptions.AccountID = Accounts.AccountID AND
    CASE
    WHEN Warnings.Direction=0 THEN Accounts.Ask < Warnings.Rate
    WHEN Warnings.Direction=1 THEN Accounts.Ask > Warnings.Rate
    END
    WHERE (Warnings.Active = 1)
    This doesn't work, but could it, or am I barking up the wrong tree?
    Not sure I'm expressing myself understandably here, but the point is to return all true Warnings, regardless of whether it's '1.0828 < 1.0900' or '1.0828 > 1.0800' as both are true at the same time. Any way to fix this?
    TIA!
    Dennis

    I think this is what you're looking for...
    SELECT
    w.WarningID,
    s.UserID,
    a.AccountName,
    a.Ask,
    w.Direction,
    w.Rate,
    w.Active
    FROM
    Warnings w
    INNER JOIN Subscriptions s
    ON w.SubscriptionID = s.SubscriptionID
    INNER JOIN Accounts a
    ON s.AccountID = a.AccountID
    WHERE
    w.Active = 1
    AND 1 = CASE
    WHEN w.Direction = 1 AND a.Ask > w.Rate THEN 1
    WHEN w.Direction = 0 AND a.Ask < w.Rate THEN 1
    ELSE 0
    END
    HTH,
    Jason
    Jason Long

  • Need assistance with conditional join in SQL

    Hi All -
    I need to ask for help with this query:
    Create table user_tab_col_test (table_name varchar2(30), column_name varchar2(30), data_type varchar2(30));
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column3', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column4', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column3', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
    Commit;
    Create table all_cons_columns_test (table_name varchar2(30), column_name varchar2(30), constraint_name varchar2(30))
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ('table1', 'column1', 'primary')
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ('table1', 'column1', 'secondary')
    Commit;
    This is my query and the current result:
    Select u.table_name, u.column_name, c.constraint_name
    From user_tab_col_test u
    Left outer join all_cons_columns_test c
    On ( u.table_name = c.table_name
    AND U.COLUMN_NAME = C.COLUMN_NAME
    AND C.CONSTRAINT_NAME IN ('primary'))
    order by U.table_name, U.COLUMN_NAME;
    TABLE_NAME COLUMN_NAME CONSTRAINT_NAME
    table1 column1 primary
    table1 column2
    table1 column3
    table2 column1
    table2 column2
    Three questions:
    1) I only want to return results where table_name = 'table1'. I can't seem to get this to work.
    2) Is my query proper and is this the best way to return my desired results? I.e. I want all columns from user_tab_col_test and I only want to display the constraint_name from all_cons_columns_test if the constraint_name = 'primary'.
    3) Will the synatx be the same if I need to join a third table to all_cons_columns_test?
    Any advice/suggestions are much appreciated -
    john
    Edited by: user703358 on Jan 11, 2013 8:57 PM
    Edited by: user703358 on Jan 11, 2013 9:48 PM

    Hi,
    user703358 wrote:
    ... ALL_CONSTRAINTS_TEST joins to ALL_CONS_COLUMNS_TEST on TABLE_NAME and CONSTRAINT_NAME. If you adapt this to use the data dictionary views ALL_CONSTRAINTS and ALL_CONS_COLUMNS, then rememeber to join on the OWNER column, also.
    Ultimately I want to use ALL_CONSTRAINTS_TEST.CONSTRAINT_TYPE = 'P' in my WHERE clause, instead of C.CONSTRAINT_NAME IN (primary), only because the constraint_type is a more definitive attribute than just the name of the constraint.
    I tried something like the query below but I'm getting
    ORA-00904: "U"."COLUMN_NAME": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:  
    *Action:
    Error at Line: 8 Column: 16Errors like that are caused by trying to mix old join syntax with ANSI join syntax in the same query.
    SELECT    u.table_name
    ,       u.column_name
    ,       C.CONSTRAINT_NAME
    FROM           USER_TAB_COL_TEST      U,
    ALL_CONSTRAINTS_TEST ACAbove is an example of an old-style join: there is a comma between the table names, and the join conditions are included in the WHERE clause below.
    LEFT OUTER JOIN  all_cons_columns_test  c
    ON    u.table_name    = c.table_name
    AND   U.COLUMN_NAME    = C.COLUMN_NAMEThis is an example of an ANSI-style join: the keyword JOIN appears between the table names, and the join conditions are right here, after the keyword ON.
    WHERE      U.TABLE_NAME    = 'table1'
    AND C.TABLE_NAME = AC.TABLE_NAME
    AND C.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
    and AC.CONSTRAINT_TYPE = 'P'
    ORDER BY  u.table_name
    ,           u.column_name
    ;While it is possible to use both join styles in the same query, it's a really bad idea. I suggest always using ANSI syntax, especially for outer joins, but whatever style you choose, use it consistently for all joins in the same query.
    In this case, you want an inner join between tablec c and ac, so the ANSI syntax would be something like
    FROM  u  LEFT OUTER JOIN c ON ... JOIN ac ON ...In this case, it's very important that the inner join between c and ac is done before the outer join with u. How can you make sure that happens? Well, if you have an arithmetic expression such as
    12 * 5 - 1and you want to make sure the subtraction of 1 from 5 takes place before the multiplication by 12, what do you do? You can add parentheses:
    12 * ( 5 - 1 )In ANSI join syntax, you can use parentheses the same way:
    FROM  u  LEFT OUTER JOIN ( c ON ... JOIN ac ON ... )or, in full:
    SELECT    u.table_name
    ,        u.column_name
    ,        c.constraint_name
    ,       ac.constraint_type
    FROM             user_tab_col_test      u
    LEFT OUTER JOIN  (
                             all_cons_columns_test  c
               JOIN  all_constraints_test   ac
                                 ON   ac.table_name     = c.table_name
                          AND  ac.constraint_name     = c.constraint_name
                            ON    u.table_name       = c.table_name
                   AND   u.column_name       = c.column_name
                   AND   ac.constraint_type  = 'P'
    WHERE       u.table_name     = 'table1'
    ORDER BY  u.table_name
    ,            u.column_name
    ;Output:
    TABLE_NAME COLUMN_NAME CONSTRAINT_NAME CONSTRAINT_TYPE
    table1     column1     primary         P
    table1     column2
    table1     column3
    table1     column4

  • Data Foundation table joins with filters (multi-conditional joins)

    My environment: Crystal Server 2011, Business View Manager 14.0.2.364, Crystal Reports 2011 with SP2 and FP28
    In our existing database we make use of a single lookup table for many different types of selection lists.
    For example, the lookup table might have selections for all of the US States (ex: NonUniqueIDValue = 123,  Value1=TX, Value2=Texas, LookupType=US_STATES) and another list of selections for OrderStatus (ex: NonUniqueIDValue = 123,   Value1=OPEN, Value2=NULL, LookupType=ORDER_STATUS).
    It is necessary to supply addtional filtering on the join statement since the IDVaule for these entries are NOT unique.
    Using SQL written joins for the two examples above would look like this:
    join lookupTable on lookupTable.NonUniqueIDValue = mainTable.US_StateID AND lookupTable.LookupType = 'US_STATES'
    join lookupTable on lookupTable.NonUniqueIDValue = mainTable.OrderStatus AND lookupTable.LookupType = 'ORDER_STATUS'
    I am new to Business Views and don't readily see a solution since it appears the DF Linking window only suports single basic conditional testing (<, >, =, etc) . How can I accomplish this in my DF or elsewhere in the BV?
    I would greatly appreciate any feedback or insight anyone might have on how to accomplish these kinds of filtered joins.
    Thanks in advance...

    Hi Paul
    If the query returns 100,000,000 rows, there will be performance issues of the report based on the connection and the datasource you are using.
    If you use a Command Object or a Stored Procedure the query will be directly executed at the database level and the performance will not be affected much.
    Hope this helps!
    Thanks

  • Conditional Join in MAP

    Hi,
    Is there a way to have a map with 2 tables but join them conditionally.
    Need to Update Table C using Table A but join TABLE B only certain condition is met. I can achieve it using PL/SQL procedure by creating Dynamic Select Statements. Can it be done with Maps ?
    Appreciate you help in this regard.
    -V

    Carsten Herbe wrote:
    Hi,
    I would not recommend using views in owb mappings. With views you just hide the complexity of mappings outside the owb, i.e. you cannot tell from the mappings where your data is coming from. You also lose some benefits from lineage analysis.
    Regards,
    Carsten.Ops,
    i would leave it to you to decide whats best for him based on complexity of the mapping , business & strategic approach etc. There are pros and cons and the approach that is best suited to your business should be adopted.
    Quote
    ====
    My advice would be to try and convert your data source to a relational table/view and using the mapping editor. This will allow you to benefit from the many new features within OLAP cube storage such as compressed composites, data compression, paralled processing, partitioning and aggregation maps.
    UnQUOTE
    ======
    This Quote is coming straight from OWB product development Manager from Oracle.
    Also the point made by Carsten needs to be considered.

  • Need help with conditional join....

    Table 1 - Student
    ID# Name
    1 # A
    2 # B
    3 # C
    4 # D
    Table2 - Marks
    ID Marks Display
    1 # 10 # Y
    1 # 20 # Y
    1 # 14 # N
    2 # 12 # N
    2 # 13 # N
    3 # 12 # Y
    Result...Need query to do this?..
    Want to join above two tables and display marks as X when there is no ID in table marks or there is ID but all marked with display as 'N'...if there is one or more
    marked with Y then display with marks..
    I am using oracle 11i.
    ID NAme      Marks
    1 # A     #     10
    1 # A     #     20
    2 # B # X
    3 # C # 12
    4 # D # X

    Or, using ANSI join syntax:
    with Table1 as (
                    select 1 id,'A' name from dual union all
                    select 2,'B' from dual union all
                    select 3,'C' from dual union all
                    select 4,'D' from dual
         Table2 as (
                    select 1 id,10 marks,'Y' display from dual union all
                    select 1,20,'Y' from dual union all
                    select 1,14,'N' from dual union all
                    select 2,12,'N' from dual union all
                    select 2,13,'N' from dual union all
                    select 3,12,'Y' from dual
    -- end of on-the-fly data sample
    select  t1.id,
            name,
            nvl(to_char(marks),'X') marks
      from      Table1 t1
            left join
                Table2 t2
              on (
                      t2.id = t1.id
                  and
                      display = 'Y'
      order by id
            ID NAME                                                    MARKS
             1 A                                                       10
             1 A                                                       20
             2 B                                                       X
             3 C                                                       12
             4 D                                                       X
    SQL> SY.

  • Conditional Join - Specific Column Select

    hi
    I just receive a request from Finance Team to retrieve customer address from Account, Agent and Customer table. here is the requirement
    1. when the customer is direct call in, use customer number from account table to get the address form customer table
    2. when the customer is walk in, use agent number from account table to get the customer number from agent table then get the address from customer table.
    how can I write the query to get those information?

    >> I just receive a request from Finance Team to retrieve customer address from Account [sic], Agent [sic] and Customer [sic] table. here is the requirement <<
    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You failed! A table is a set, so its name has to be plural or collective.
    You are telling us that you have one account, one agency and one customer. Back in the 1950's, before RDBMS, we had file systems that process records, one at a time. The early system design methods used singular file names because that was the “unit of work”
    back then. 
    You should follow ISO-8601 rules for displaying temporal data. We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. 
    How do you write SQL without DDL?? You expect us to do this for you, but please tell us how! Or quite being rude to the forum members. 
    >> 1. when the customer is direct call in, use customer number from account [sic] table to get the address from customer [sic] table
    2. when the customer is walk in, use agent number from account [sic] table to get the customer number from agent [sic] table then get the address from customer [sic] table.
    <<
    Why are addresses in two places and treated as attributes? Do you know what normalization is? Should you have a table of them then reference the addresses in other tables. Does your industry use a SAN (Standard Address Number) system? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Conditional join statements

    I have two tables Employee and Salary.  
    Employee ( EmpId, Name, DeptID, TeamID, CurrentSalary, HireDate, etc...)
    Salary (DeptID, TeamID, Tenure, IncreasePercent, BonusAmt, etc...)
    The scenario is
    if the emp1 in IT dept and team1, and he/she have been worked 1-5 yrs, then current salary increases 5%.
    if the emp2 in IT dept and team1, and worked 10 yrs, then increases 10%
    if the emp3 in IT dept and team2, and worked 1-5 yrs, then increases 8%
    if the emp4 in IT dept and either team1 or team2,  then use bonusAmt
    if the emp5 in HR dept and ....., then.........
    So how can I get the employee's salary of the next year? Any suggestions would appreciate.

    Thanks for your reply. The tenure is a range for years in the table.  
    Sometimes the TeamID is null,then (CurrentSalary+ bonusAmt)
    as newSalary.
    So how to deal with this case? I am struggling with this scenario. Thanks. 

  • Joining Two Tables based on Conditions.

    Hi All,
    i would like to join two tables emp and dept with conditional join like
    for example: select emp.column1...............
    left outer join DEPT ON if Dept.column1='A" then emp.column1=dept.column1
    else emp.column2=dept.column3
    i know that bu using the UNION we can dothis, but i donot want to USE UNION.
    please let me know if any workaround for this.
    Thanks,
    Kalyan

    SQL> select * from etl
      2  /
         EMPNO ENAME      JOB              MGR        SAL       COMM     DEPTNO AAA                     DEPT_NO
          7566 JONES      MANAGER         7839       2975                    20 2                         20
          7654 MARTIN     SALESMAN        7698       1250       1400         30 3                         10
          7698 BLAKE      MANAGER         7839       2850                    30 3                         10
          7782 CLARK      MANAGER         7839       2450                    10 1                         20
          7788 SCOTT      ANALYST         7566       3000                    20 2                         20
          7839 KING       PRESIDENT                  5000                    10 1                         20
          7844 TURNER     SALESMAN        7698       1500                    30 3                         10
          7876 ADAMS      CLERK           7788       1100                    20 2                         20
          7900 JAMES      CLERK           7698        950                    30 3                         10
          7902 FORD       ANALYST         7566       3000                    20 2                         20
          7934 MILLER5    CLERK           7782       1300                    10 1                         20
          7936 MILLER7    CLERK           7782       1300                    10 1                         20
    12 rows selected.
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> ed
    Wrote file afiedt.buf
      1  select
      2     e.empno,
      3     e.ename,
      4     e.deptno,
      5     aaa,
      6     e.dept_no,
      7     d.deptno,
      8     d.dname
      9  from
    10     etl e ,
    11     dept d
    12  where
    13     (e.aaa =1 and e.deptno = d.deptno) or
    14*    (e.aaa =2 and e.dept_no =d.deptno)
    SQL> /
         EMPNO ENAME          DEPTNO AAA                     DEPT_NO     DEPTNO DNAME
          7566 JONES              20 2                            20         20 RESEARCH
          7788 SCOTT              20 2                            20         20 RESEARCH
          7876 ADAMS              20 2                            20         20 RESEARCH
          7902 FORD               20 2                            20         20 RESEARCH
          7782 CLARK              10 1                            20         10 ACCOUNTING
          7839 KING               10 1                            20         10 ACCOUNTING
          7934 MILLER5            10 1                            20         10 ACCOUNTING
          7936 MILLER7            10 1                            20         10 ACCOUNTING
    8 rows selected.Regards
    Singh

  • Framing Join Condition

    Hi,
    I have a requirement to frame the where condition in the select stmt,
    the below one is a logical join condition
    JOIN BCAR_DETAIL_ADJ to STG_FIN_ACC via ACC_RK,
    JOIN STG_FIN_ACC to
    JOIN STG_FIN_ACC_PARTY_SRC to STG_PARTY_SRCD via Party_SRC_RK
    Where STG_FIN_ACC_PARTY_SRC.party_role_cd = 'BOR'
    When multiple records return of the subjoin, select the one with
    MAX(FINANCIAL_ACC_PARTICIPANT.Party_SRC_RK)
    ) via ACC_RK
    and i framed the join like this,
    WHERE B.ACC_RK = SF.ACC_RK
    AND SF.ACC_RK =
    SELECT ST.ACC_RK FROM
    STG_FIN_ACC_PARTY_SRC ST,STG_PARTY_SRC SP
    WHERE ST.PARTY_SRC_RK = SP.PARTY_SRC_RK
    AND ST.PARTY_ROLE_CD = 'BOR'
    AND ST.PARTY_SRC_RK =
    (SELECT MAX(FCC.PARTY_SRC_RK)
    FROM FINANCIAL_ACC_PARTICIPANT FCC)
    I dont know i have formed the join condition correctly.
    Can anyone help me in this
    Thnx
    Rad

    Hi, Rad,
    I see only one syntax error: you're missing parentheses around the outer scalar sub-query.
    Perhaps you meant something like this:
    WHERE     B.ACC_RK     = SF.ACC_RK
    AND     SF.ACC_RK     = (
                     SELECT     ST.ACC_RK
                     FROM          STG_FIN_ACC_PARTY_SRC     ST
                     ,          STG_PARTY_SRC          SP
                     WHERE          ST.PARTY_SRC_RK          = SP.PARTY_SRC_RK
                     AND          ST.PARTY_ROLE_CD     = 'BOR'
                     AND          ST.PARTY_SRC_RK          = (
                                                SELECT     MAX (FCC.PARTY_SRC_RK)
                                              FROM          FINANCIAL_ACC_PARTICIPANT     FCC
                     )Sorry, I don't understand the pseudo-code in the first part of your message, so I can't say if the real code in the second half does it or not.
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type these 6 characters
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.

  • What are the joins are available in abap.

    Hi all,
    What are all the joins are avaialble in abap. Can anyone explain me with examples.
    thanxs in advance
    hari

    Hi,
    There are two types of JOINS
    INNER JOINS and OUTERJOINS
    In the case of INNER JOIN only the records from tables for which the JOIN condition is met are retrieved.
    In the case of OUTER JOIN you will get all the fields that are there in the LEFT table irrespective of the join condition.
    Syntax
    ... [(] {dbtab_left [AS tabalias_left]} | join
    {[INNER] JOIN}|{LEFT [OUTER] JOIN}
    {dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
    Effect
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN . Depending on the type of join, a join expression can be either an inner ( INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following language elements may not be used: BETWEEN, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
    p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
    fldate TYPE sflight-fldate,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.
    Joins are used to fetch data fast from Database tables:
    Tables are joined with the proper key fields to fetch the data properly.
    If there are no proper key fields between tables don't use Joins;
    Important thing is that don't USE JOINS FOR CLUSTER tableslike BSEG and KONV.
    Only use for Transparenmt tables.
    You can also use joins for the database VIews to fetch the data.
    JOINS
    ... FROM tabref1 [INNER] JOIN tabref2 ON cond
    Effect
    The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
    In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
    Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Inner Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID
    WHERE FCONNID = PCONNID
    AND P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Left Outer Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a3
    b3
    c3
    2
    NULL
    NULL
    NULL
    NULL
    NULL
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all custimers with their bookings for October 15th, 2001:
    DATA: CUSTOMER TYPE SCUSTOM,
    BOOKING TYPE SBOOK.
    SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
    SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
    INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID)
    FROM SCUSTOM LEFT OUTER JOIN SBOOK
    ON SCUSTOMID = SBOOKCUSTOMID AND
    SBOOK~FLDATE = '20011015'
    ORDER BY SCUSTOMNAME SBOOKFLDATE.
    WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
    Note
    For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
    Only a table or view may come after the JOIN operator, not another join statement.
    The only logical operator allowed in the ON condition is AND.
    Each comparison in the ON condition must contain a field from the right-hand table.
    Comparisons in the WHERE condition must not contain a field from the right-hand table.
    The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
    Note
    In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
    Example
    Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
    DATA: BEGIN OF WA,
    FLIGHT TYPE SFLIGHT,
    PFLI TYPE SPFLI,
    CARR TYPE SCARR,
    END OF WA.
    SELECT * INTO WA
    FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID )
    INNER JOIN SCARR AS C
    ON FCARRID = CCARRID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
    WA-FLIGHT-CONNID.
    ENDSELECT.
    Regards,
    Priyanka.

  • Cartesian join in the SQL query

    Hi,
    I have a problem when joining two tables that cannot join directly. As I read (please correct me if I'm wrong), two dims have to join by one fact in order to extract information from them. This way, I created logical source tables with SQL query that join both dims. So, if for example Dim A and Dim B cannot join directly, I created a "mapping table" which is a select that joins these 2 tables in the proper way and the fields are the row_wids from these tables. This way, I created the following model diagram for this relationship:
    DimActivity -< FactMapping >- DimPNR
    DimActivity -< FactActivity >- DimMapping
    DimPNR -< FactPNR >- DimMapping
    Now, I can extract information from both dims and their metrics, except in one case; If I extract info from ("Segment Designer") "Dim-Activity", "Dim-PNR", "Fact-Activity" and "Fact-PNR", I get a query that first calculates the metric from Activity, then calculates the metric from PNR, and when it joins both queries, I get cardinality because it doesn't join through the "mapping tables". The whole query is:
    WITH
    SAWITH0 AS (select sum(T690608."QTY") as c1,
    T690608."ASSET_NUM" as c2
    from "W_ASSET_D" T690608 /* Dim_W_ASSET_D */
    group by T690608."ASSET_NUM"),
    SAWITH1 AS (select sum(T682428."COST") as c1,
    T682428."STATUS_WID" as c2
    from "W_ACTIVITY_F" T682428 /* Dim_W_ACTIVITY_F */
    group by T682428."STATUS_WID")
    select distinct SAWITH0.c2 as c1,SAWITH1.c2 as c2,SAWITH1.c1 as c3,SAWITH0.c1 as c4
    from
    SAWITH0,SAWITH1
    Why there is no condition joining SAWITH0 and SAWITH1? Is there a way to force this to be an inner join? I'm looking forward to your answer, since this problem is urgent within this project. Thank you in advance

    Ok.
    I assume that you have for one activity several asset PNR and for one asset several activity.
    The factPNR is on this way a real bridge table. It's a way to be able to design a many-to-many relationship.
    Have a look here for more detail on how to build a many-to-many relationship :
    http://gerardnico.com/wiki/dw/data_quality/relationships#many-to-many
    Therefore I assume that you want this design :
    DimActivity -< FactActivity >- < FactPNR >- DimPNR  and you will have :
    DimActivity -< FactActivity >- < BridgeTable >- DimPNR  How to build your bridge table ?
    In the physical layer, :
    * create a new table BridgeActivityPNR, open it and select "statement"
    * enter your sql statement
    SELECT DISTINCT A.ROW_WID ACTIVIDAD_WID, B.ROW_WID ASSET_WID
    FROM W_ACTIVITY_F A,
    W_ASSET_D B,
    W_SRVREQ_D C,
    X_S_CMPT_MTRC_F D,
    X_S_ASSET_FEA_D E
    WHERE A.X_SRA_SR_ID=C.INTEGRATION_ID AND
    C.X_VLG_FLIGHT_ID=D.X_ROW_ID AND
    D.X_ROW_ID=E.X_CM_ID AND
    E.X_ASSET_ID=B.X_ROW_ID* add two columns in the column tab : ACTIVIDAD_WID and ASSET_WID
    * create the physical join with the table FactActivity and DimPNR
    * drag and drop in the business model your table BridgeActivityPNR
    * in the BMM, create the complex join like this :
    DimActivity -< FactActivity >- < BridgeTable >- DimPNR  * open your logical bridge table and check the bridge table option.
    And you are done if I didn't forget anything.
    A complete example here :
    http://gerardnico.com/wiki/dat/obiee/obiee_bridge_table

  • Joins in abap programming

    hi
       i am a fresher and i have a question. how many joins can program have.

    Hi Jaya,
    ABAP has two Joins.
    INNER  JOIN  and  OUTER JOIN.
    Check out the post :
    JOINS and Matchcodes
    IF you press F1 on JOIN statement ,it has explained really good.I am pasting the same for you.
    ... FROM tabref1 [INNER] JOIN tabref2 ON cond
    Effect
    The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
    In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
    Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Inner Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID
    WHERE FCONNID = PCONNID
    AND P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Left Outer Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a3
    b3
    c3
    2
    NULL
    NULL
    NULL
    NULL
    NULL
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all custimers with their bookings for October 15th, 2001:
    DATA: CUSTOMER TYPE SCUSTOM,
    BOOKING TYPE SBOOK.
    SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
    SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
    INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID)
    FROM SCUSTOM LEFT OUTER JOIN SBOOK
    ON SCUSTOMID = SBOOKCUSTOMID AND
    SBOOK~FLDATE = '20011015'
    ORDER BY SCUSTOMNAME SBOOKFLDATE.
    WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
    Note
    For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
    Only a table or view may come after the JOIN operator, not another join statement.
    The only logical operator allowed in the ON condition is AND.
    Each comparison in the ON condition must contain a field from the right-hand table.
    Comparisons in the WHERE condition must not contain a field from the right-hand table.
    The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
    Note
    In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
    Example
    Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
    DATA: BEGIN OF WA,
    FLIGHT TYPE SFLIGHT,
    PFLI TYPE SPFLI,
    CARR TYPE SCARR,
    END OF WA.
    SELECT * INTO WA
    FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID )
    INNER JOIN SCARR AS C
    ON FCARRID = CCARRID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
    WA-FLIGHT-CONNID.
    ENDSELECT.
    Regards,
    Priyanka.

Maybe you are looking for

  • Installation of 8.1.6 on solaris 8

    Hi all, Has any one tried installing Oracle 8.1.6 on solaris 8. The installation guide says it is supported only by 2.6 and solaris 7. Any help would be appreciated. Thanks

  • Why greyed out options in iTunes radio, and other behavior

    iOS 7.1.2 on a 4S. In the past couple of days, when accessing the 'star' menu on the lower left hand side, the "play more like this" and "never play this again" are greyed out. Naturally, I can certainly "add to my wish list", because that will event

  • How to compare string in a table reg

    Hi all, I need a solution of this requirement. i have Table reqtab Code sql: sql>select * FROM reqtab; REID EMAILADDRESS 72 [email][email protected][email] 72 [email][email protected][email] 75 [email][email protected][email] 75 [email][email protect

  • Non-static method cannot be referenced from a static context

    Hey Im not the best java programmer, im trying to teach myself, im writing a program with the code below. iv run into a problem, i want to call the readFile method but i cant call a non static method from a static context can anyone help? import java

  • Skype recording messages and calls?

    Salutations. So today I'm going to confront you with a hypothesis I've composed. Back before Skype had been bought from Microsoft, they had recorded calls and messages and stored them away. Those mentioned things would get run through their system. I