Inner Join question

I have assignment for sql query by asking list all products where designer of product lives in the same region as supplier of the product. However, I have no clue to solve it. Please assist.
Below are 4 tables I created:
CREATE Table REGION
RegCode          Varchar2 (8),
RegName          Varchar2 (40),
ShipDays          Number (2),
PRIMARY KEY     (RegCode)
CREATE Table SUPPLIER
SuppCode          Number (3),
SuppName          Varchar2 (50),
Rating          Varchar2 (1),
RegCode          Varchar2 (8),
PRIMARY KEY      (SuppCode),
FOREIGN KEY     (RegCode) REFERENCES REGION
CREATE table DESIGNER
FirstName          Varchar2 (30),
Surname          Varchar2 (30),
Email          Varchar2 (45),
Gender          Varchar2 (1),
RegCode          Varchar2 (8),
PRIMARY KEY     (FirstName, Surname),
FOREIGN KEY     (RegCode) REFERENCES REGION
CREATE table      PRODUCT
ProdCode          Varchar2 (3),
ProdName          Varchar2 (35),
SellingPrice     Varchar2 (4),
CostPrice          Varchar2 (4),
FirstName          Varchar2 (30),
Surname          Varchar2 (30),          
SuppCode          Number (3),
PRIMARY KEY     (ProdCode),
FOREIGN KEY      (FirstName,Surname) REFERENCES DESIGNER,
FOREIGN KEY      (SuppCode)     REFERENCES SUPPLIER
Thanks a ton,
Mandy

You won't need the region table at all, because the region code in supplier and designer will be enough for you to know that they are the same.
Do you know how to join tables at all?
Write your query by starting with products. Then join it to supplies using the value that is the primary key in supplier and a foreign key in products. Then, join to designer in the same manner. The only tricky thing about the second join is that you'l need two fields to complete the join. After that, you'll be ready to find records where the region code is the same.
Good luck! I hope this is enough to get you started...

Similar Messages

  • About a question using Update ... inner join ?

    select *
    FROM a
    INNER JOIN b ON a.ProductID=b.ProductID
    WHERE a.HeadID='000246'
    this statement is ok ;
    But the following statement does not work ! Why ?
    UPDATE a SET
    a.Quantity=a.PurchaseQuantity/b.ConversionGene
    FROM a
    INNER JOIN b ON a.ProductID=b.ProductID
    WHERE a.HeadID='000246'

    "Because Oracle syntactically does not support that type of construct..." Is a correct statement, but not because "It expects only one table in UPDATE statement". The synatax for an updateable join in Oracle requires a "proper" in-line view to be updated.
    As long as the table joined (in my example t1) has a declared unique constraint on the columns used to join by (in my example id), you can do it like:
    SQL> SELECT * FROM t;
            ID DESCR
             1 One
             2 Two
             3 Three
    SQL> SELECT * FROM t1;
            ID DESCR2
             1 Un
             2 Deux
    SQL> UPDATE (SELECT t.descr, t1.descr2
      2          FROM t
      3             JOIN t1 ON t.id = t1.id)
      4  SET descr = descr2;
    2 rows updated.
    SQL> SELECT * FROM t;
            ID DESCR
             1 Un
             2 Deux
             3 ThreeTTFN
    John

  • QUESTION INNER JOIN FOR UPDATE

    Dear All,
    does oracle support this sql update statement?
    UPDATE Tb1 INNER JOIN Tb2 ON Tb1.empid = Tb2.empid2 SET
    Tb2.salary = Tb1.salary * 0.5
    Best Regards
    Terence Chua

    No - because you are trying to update the salary in Tb2
    in an update statement for TB1
    If you are trying to update the salary in T1 based on the salary in T2, use the following
    UPDATE Tb1
    set Tb1.salary = (
    select TB2.salary * 0.5
    from TB2
    where TB2.empid2 = TB1.empid
    However, I am wondering if you have your model confused.
    Can you please confirm that you have two separate tables.
    TB1 has column EMPID
    TB2 has column EMPID2
    or - are TB1 and TB2 the same table
    If they are the same table - please confirm if you have one EMPID column - or an EMPID column and an EMPID2 columns.

  • Data is not fetching in inner join

    Hi Experts,
    I developed a select query using inner joins, all the fields data is gettting appended, but one field DISPO data is not getting appeneded. please check the innerjoin and suggest me ur soluitons.
    MODULE GET_DATA OUTPUT.
      select   arbpl
             sptag
             aufnr
             plnum
             posnr
             plnfl
             werks  from s022
                        into table it_s022
                         where arbpl in s_arbpl
                          and  werks in s_werks
                          and  sptag in s_sptag
                          and  matnr in s_matnr.
    if sy-subrc eq 0.
    select a~aufnr
           a~posnr
           a~kdauf
           a~pgmng
           a~plnum
           a~strmp
           b~plnty
           b~gamng
           b~igmng
           b~iasmg
           b~rmnga
           b~gstrp
           b~rsnum
           b~plnbez
           b~dispo
           c~maktx
           b~plnnr
           b~plnty
           b~zaehl
           d~vornr
           d~ltxa1
           b~aufpl
           b~aplzt
           e~astnr
           into corresponding fields of table it_afpo from  afko as b
                    inner join afpo as  a
                     on a~aufnr = b~aufnr
                    inner join makt as c
                     on b~plnbez = c~matnr
                    inner join plpo as d
                     on b~plnnr  = d~plnnr
                      and b~plnty = d~plnty
                      and b~zaehl  = d~zaehl
                     inner join aufk as e
                      on b~aufnr = e~aufnr
                    inner join marc as f
                     on bplnty = fmatnr
                    for all entries in it_s022
                     where b~aufnr = it_s022-aufnr.
                         and e~erdat = it_s022-sptag
                     and  a~posnr = it_s022-posnr
                    and  a~plnum = it_s022-plnum .  .
      if sy-subrc eq 0.
        it_afpo1[] = it_afpo[].
        sort it_afpo1 by aufpl." aplzt."""
        delete ADJACENT DUPLICATES FROM it_afpo1 COMPARING aufpl." aplzt ."""
        select aufpl
               aplzl
               fsavd
               fsavz
               ssedd
               ssedz
               mgvrg
                FROM  afvv  INTO TABLE It_afvv
                               FOR ALL ENTRIES IN IT_afpo1
                               WHERE aufpl = IT_afpo1-aufpl.
                                and aplzl = it_afpo1-aplzt.
       endif.
    loop at it_afpo into wa_afpo.
    DATA : G_SLNO(8) TYPE C.
    G_SLNO = G_SLNO + 1.
    wa_afpo-slno = g_slno.
        move-corresponding wa_afpo to wa_final.
       move-corresponding wa_afko to wa_final.
      read table it_afvv into wa_afvv with key
                aufpl = wa_afpo-aufpl binary search."aplzl = wa_afpo-aplzt binary search."""
    *read table it_afko into wa_afko with key aufnr = wa_final-aufnr.
      IF SY-SUBRC EQ 0.
        move-corresponding wa_afvv to wa_final.
    bal_qty = wa_final-gamng - wa_final-igmng.
        move : wa_afpo-slno  to wa_final-slno,
               wa_afpo-aufnr to wa_final-aufnr,
               wa_afpo-posnr to wa_final-posnr,
               wa_afpo-kdauf to wa_final-kdauf, " Sales order Number
               wa_afpo-pgmng to wa_final-pgmng, " Order item qty
               wa_afpo-plnum to wa_final-plnum, " Planned  Order Qty
               wa_afpo-strmp to wa_final-strmp, " Planned Order Date
               wa_afpo-gstrp to wa_final-gstrp, " Basic Finish  date
               wa_afpo-rsnum to wa_final-rsnum, " Number of Reservation
               wa_afpo-plnbez to wa_final-plnbez, " Material Number
               wa_afpo-maktx to wa_final-maktx,
               wa_afpo-plnnr to wa_final-plnnr,
               wa_afpo-plnty to wa_final-plnty,
               wa_afpo-zaehl to wa_final-zaehl,
               wa_afpo-vornr to wa_final-vornr,
               wa_afpo-ltxa1 to wa_final-ltxa1,
               wa_afpo-aufpl to wa_final-aufpl,
               wa_afvv-fsavd to wa_final-fsavd,
               wa_afvv-fsavz to wa_final-fsavz,
               wa_afvv-ssedd to wa_final-ssedd,
               wa_afvv-ssedz to wa_final-ssedz,
               wa_afvv-mgvrg to wa_final-mgvrg,
               wa_afko-igmng to wa_final-igmng,
               wa_afko-iasmg to wa_final-iasmg,
               wa_afko-rmnga to wa_final-rmnga,
               wa_afko-dispo to wa_final-dispo,
              wa_afko-bal_qty to wa_final-bal_qty,
               wa_aufk-astnr to wa_final-astnr,
               wa_afpo-text  to wa_final-text.
    *bal_qty = wa_final-gamng - wa_final-igmng.
    *bal_qty = wa_afko-bal_qty.
      endif.
      append wa_final to it_final.
      clear:wa_final ,wa_afpo,wa_afvv,wa_aufk,wa_afko.
    endloop.
    endif.
    ENDMODULE.                 " GET_DATA  OUTPUT
    *&      Module  DISPLAY_DATA  OUTPUT
          text
    MODULE DISPLAY_DATA OUTPUT.
      IF REF_CONTAINER IS INITIAL.
         PERFORM FIELD_CAT.
      CREATE OBJECT REF_CONTAINER
      EXPORTING
           PARENT                      =
        CONTAINER_NAME              = 'CUSTOM_CONTROL'
           STYLE                       =
           LIFETIME                    = lifetime_default
           REPID                       =
           DYNNR                       =
           NO_AUTODEF_PROGID_DYNNR     =
          EXCEPTIONS
            CNTL_ERROR                  = 1
            CNTL_SYSTEM_ERROR           = 2
            CREATE_ERROR                = 3
            LIFETIME_ERROR              = 4
            LIFETIME_DYNPRO_DYNPRO_LINK = 5
            others                      = 6
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      L_LAYO-ZEBRA = 'X'.
      L_LAYO-GRID_TITLE = 'JOB CARD'.
      data: variant type disvariant.
      CREATE OBJECT REF_ALV_GRID
        EXPORTING
           I_SHELLSTYLE      = 0
           I_LIFETIME        =
          I_PARENT          = REF_CONTAINER
           I_APPL_EVENTS     = space
           I_PARENTDBG       =
           I_APPLOGPARENT    =
           I_GRAPHICSPARENT  =
           I_NAME            =
           I_FCAT_COMPLETE   = SPACE
          EXCEPTIONS
            ERROR_CNTL_CREATE = 1
            ERROR_CNTL_INIT   = 2
            ERROR_CNTL_LINK   = 3
            ERROR_DP_CREATE   = 4
            others            = 5
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    l_variant-report = sy-cprog.
    *data: l_prnt type lvc_s_prnt.
    *l_prnt-print = 'X'.
      SORT T_FCAT.
      call method ref_alv_grid->set_ready_for_input
       exporting
        i_ready_for_input = 1.
    create object event_receiver.
       set handler event_receiver->handle_top_of_page for ref_alv_grid.
      CALL METHOD REF_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
           EXPORTING
           I_BUFFER_ACTIVE               =
           I_BYPASSING_BUFFER            =
           I_CONSISTENCY_CHECK           =
           I_STRUCTURE_NAME              =
            is_variant                     =  variant   "l_variant
            i_save                        = 'X'
           I_DEFAULT                     = 'X'
             IS_LAYOUT                     = L_LAYO
           IS_PRINT                      =
           IT_SPECIAL_GROUPS             =
           IT_TOOLBAR_EXCLUDING          =
           IT_HYPERLINK                  =
           IT_ALV_GRAPHICS               =
           IT_EXCEPT_QINFO               =
           IR_SALV_ADAPTER               =
        CHANGING
          IT_OUTTAB                     = IT_final[]
          IT_FIELDCATALOG               = T_FCAT
           IT_SORT                       =
           IT_FILTER                     =
          EXCEPTIONS
            INVALID_PARAMETER_COMBINATION = 1
            PROGRAM_ERROR                 = 2
            TOO_MANY_LINES                = 3
            others                        = 4
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
       create object g_event_receiver.
       set handler g_event_receiver->handle_user_command for ref_alv_grid.
       set handler g_event_receiver->handle_toolbar for ref_alv_grid.
    § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
       call method ref_alv_grid->set_toolbar_interactive.
       call method cl_gui_control=>set_focus exporting control = ref_alv_grid.
    ENDIF.
    ENDMODULE.                 " DISPLAY_DATA  OUTPUT
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN001'.
    SET TITLEBAR 'xxx'.
    Regards,
    Bharath Kumar

    I agree with Shiva Kumar - most likely there is no such field in it_afpo. A few more suggestions though:
    1) Do not post large pieces of code here - if you have a question about a particular SELECT statement, post only that statement and relevant data definitions. No one is going to read your whole program  anyway - we have work to do too.
    2) Your JOIN is way too big and would be difficult to analyze if anything goes wrong. You might want to start with smaller SELECTs and, when you're sure everything is working correctly, then combine them into one. Also huge JOINT is not necessarily more efficient.
    3) You don't have to use aliases "AS a... AS b", etc. Instead, just use the table name, e.g. AFKO... AFPO... .It is much easier to read this way. The aliases are needed only if you're joining the same table more than once. Also they're not limited to one letter either.

  • Inner Join resulting in many, many duplicates

    I ran an Inner Join but it returned many, many duplicates. Any idea why that would occur?
    One Answer from a different thread:
    Because you may be having improper Join condition what has a One to many or a Many to many relationship between the tables. We do not have the data, and hence cannot comment over it. However, since the original issue is resolved, I suggest you close this thread and ask the question in another thread.
    What do I look for to identify an improper join?

    Please don't start another discussion for the same issue.
    Continue on your existing thread where the answers and advice you've already been given can be seen, so that people don't end up giving the same advice you've already had.
    Answers on other thread: Inner Join error
    Locking this thread

  • How to use BKPF and BSEG without using  inner join

    Hi,
    can anybody plz tell me the logic about how to complete the report without inner joining bkpf and bseg.Is this report can be really be made by using only bseg,bkpf ?
    *selection-criteria .
    BKPF-USNAM
    BKPF-CPUDT
    BKPF-BUDAT
    BKPF-GJAHR
    BKPF-BUKRS
    BKPF-BELNR
    BSEG-SAKNR
    BSEG-LIFNR
    BSEG-KUNNR
    BSEG-ZUONR
    BSEG-SGTXT
    Output fields required.
    BKPF-BUKRS
    BKPF-BELNR
    BKPF-GJAHR
    BKPF-MONAT
    BKPF-BLART
    BKPF-CPUDT
    BKPF-BLDAT
    BKPF-BUDAT
    BKPF-USNAM
    BKPF-XBLNR
    BKPF-STBLG
    BKPF-BKTXT
    BKPF-WAERS
    BKPF-KURSF
    BSEG-BUZEI
    BSEG-BSCHL
    BSEG-KOART
    BSEG-UMSKZ
    BSEG-SHKZG
    BSEG-MWSKZ
    BSEG-PSWBT
    BSEG-PSWSL
    BSEG-DMBTR
    BSEG-SAKNR
    BSEG-HKONT
    BSEG-KOSTL
    BSEG-KUNNR
    BSEG-VBELN
    BSEG-LIFNR
    BSEG-ANLN1
    BSEG-ANLN2
    BSEG-AUFNR
    BSEG-MATNR
    BSEG-MENGE
    BSEG-MEINS
    BSEG-ZUONR
    BSEG-SGTXT
    Thanks,
    Rahman
    Moderator Message: Please search before posting your question. Thread locked.
    Edited by: Suhas Saha on Jan 31, 2012 3:07 PM

    Quick question - what's preventing your from using built-in functions?
    I suggest mapping your Time Dim to a standard Time Dim and work with it - you'll save a lot more time. You'd even need this table if you wanted to work around Todate/AGO.
    It is possible to model this functionality w/o functions, but it'll be time consuming task, similar to using Time Series Wizard in Siebel Analytics. You'll need to build aliases and views along with some complex joins (such as TIME.KEY=TIME.KEY-365), introduce a bunch of variables to control. Also, you might not get much flexibility in terms of years. For each year, you'd need an alias table. (TIME_DIM_PY).

  • Help:Nested Inner Join

    Hello Folks,
    I have a query which has a nested Inner Join as follows
    INNER JOIN(Client
    INNER JOIN CUBS SNAPSHOT ON Client . Client = CUBS SNAPSHOT . CLIENT) ON CancelDesc . CancelReason = CUBS SNAPSHOT . CANCELREASONcouldnt figure out wat is the quivalent of this nested inner join in Oracle Server. I am trying to create a report based on this inner join of a query. Can anyone throw some light on this.
    Thanks

    Hi,
    Inner joins don't need to be nested. The results will be the same, no matter in what order the tables are joined.
    In Oracle, don't use table names with spaces in them, and don't put spaces before or after the dots that separate table name qualifiers from column names.
    I think this is what you want:
    INNER JOIN     cubs_snapshot  ON     CancelDesc.CancelReason = cubs_snapshot.cancelreason
    INNER JOIN     Client            ON     Client.Client           = cubs_snapshot.clientWhenever you have a question, post a little sample data (CREATE TABLE and INSERT statememts) for all tables invlovled, and the results you want from that data.
    If you really did need to nest joins, you could join some tables in a sub-query, then use the result set of that sub-query as if it were a table.
    For example:
    WITH  cubs_and_client            AS
         SELECT     CancelReason
         ,     ...     -- Whatever other columns are needed in superior query or queries
         FROM          client
         INNER JOIN     cubs_snapshot     ON     Client.Client           = cubs_snapshot.client
    SELECT     
    INNER JOIN     cubs_and_client     ON     CancelDesc.CancelReason = cubs_and_client.CancelReason
    ...In this example, the two tables cubs_snapshot and client are joined in a sub-query. The results of that sub-query can be referenced later in the query as if it were a table called cubs_and_client, very much like a view.

  • Inner join-select -primary key in table issue

    Hi ,
            Iam using FEBKO(header) and FEBEP(item) in inner join  select .But the datas fetching by this selct in not correct.The analysis is the is no common primary fields in the both table.
    Question 1-> Can i use inner join without common primary key in the both tables, weather it possible to make a select without common primary key in both table. Please kindly let me know.
    Question 2-> What is the other possible way to give the selct for both table(better performance)
    Regards,
    Veera

    Hi,
    When you use INNER JOIN in this case, link your tables based on KUKEY and ESNUM fields, bcoz there can be many items under a single header. So this will work for you, even from the performance point of view.
    Hope this is helpful to you. If you need further information, revert back.
    Reward all the helpful answers.
    Regards
    Nagaraj T

  • Outer join - inner joins at the level of the microcube  between 2 queries

    I have a very simple question.
    If i build 2 queries in webi on the top of the same BW query
    Query 1: Country and Revenue and we do put a filter on the query base of country = US
    Query 2: Country and Revenue and we do not have any filter on this one
    so in webi here is what happen you will get 2 tables
    one table for query 1 where you will see only data for US and then Revenue
    the second table query 2 will only retrieve data for all the countries and their revenue
    Now if i do some merging .. it sounds like it is doing an inner join
    is there a way to get the outer join or the left outer part of it or even the right out part ?
    Thanks in advance
    Philippe

    Hi Philippe,
    Yes you can.  Make sure that the Country coming from Query 2 is the one on the report. Then make sure the Revenue on the report is coming from Query 1. This should give you what you want.
    Hope that helps!
    Thanks

  • Avoiding inner joins????

    Hi all,
    I was just thinking of ways to improve the perfomance of my report. Its fetching data in to two different tables using two innerjoins and these two internal tables are again looped for some other manipulation. Can anyone tell me the ways i can avoid innerjoin or is there other ways to improve psrfomance by avoiding innejoins in general?
    Rakesh

    hi sir i was able to find out that
    Using several nested INNER JOIN statements can be inefficient and cause time out if the tables become too big in the future."
    Joins here (in ABAP) are not those Native SQL Joins.  If you are talking about the Core RDBMS, which mean Oracle or SQL Server, then Undoubtedly Joins are the best.
    In ABAP, these joins are first split by the ABAP processor and then sent to the database, with the increase in DATA in production system, these joins tend to give way if your database keeps growing larger and larger.
    You should rather used "FOR ALL ENTRIES IN" (Tabular conditions), which is a much effecient way as far as performance is concerned.
    For example :
    DATA: BEGIN OF LINE,
            CARRID   TYPE SPFLI-CARRID,
            CONNID   TYPE SPFLI-CONNID,
            CITYFROM TYPE SPFLI-CITYFROM,
            CITYTO   TYPE SPFLI-CITYTO,
          END OF LINE,
          ITAB LIKE TABLE OF LINE.
    LINE-CITYFROM = 'FRANKFURT'.
    LINE-CITYTO   = 'BERLIN'.
    APPEND LINE TO ITAB.
    LINE-CITYFROM = 'NEW YORK'.
    LINE-CITYTO   = 'SAN FRANCISCO'.
    APPEND LINE TO ITAB.
    SELECT CARRID CONNID CITYFROM CITYTO
    INTO   CORRESPONDING FIELDS OF LINE
    FROM   SPFLI
    FOR ALL ENTRIES IN ITAB
    WHERE  CITYFROM = ITAB-CITYFROM AND CITYTO = ITAB-CITYTO.
      WRITE: / LINE-CARRID, LINE-CONNID, LINE-CITYFROM, LINE-CITYTO.
    ENDSELECT.
    Do you have a ABAP Question?
    Best regards,
    SAP Basis, ABAP Programming and Other IMG Stuff

  • OUTER/INNER JOINS e.g

    Hi Gurus!
    Can anyone explain with a really simple example(using say employee- department) tables, what is OUTER join, INNER join, Left RIGHT JOINs??
    Thanks,
    sapa

    This question is only loosely related to the Oracle Migration Workbench,
    however I included some information:
    INNER JOINS are 'simple' joins where all matches, i.e. where both sides of the where clause are found, are returned.
    LEFT OUTER JOIN, RIGHT OUTER JOIN and FULL OUTER JOIN [the OUTER keyword is optional] have the unmatched column and row filled in with nulls.
    Oracle has its own (+) syntax but the new ANSI style as above in preferred, although the Oracle Migration Workbench does not generate ANSI style output yet.
    An example use is where the owner may have no manager, but you might want the owner included in your selection of a hierarchy.
    For more information see:
    Oracle9i SQL Reference
    Release 1 (9.0.1)
    Part Number A90125-01
    'SQL Queries and Other SQL Statements, 2 of 3'
    http://otn.oracle.com/docs/products/oracle9i/doc_library/901_doc/server.901/a90125/queries2.htm#2054014
    create table fulltable (col1 char(10), col2 char(10));
    create table lefttable (col1 char(10), col2 char(10));
    create table righttable (col1 char(10), col2 char(10));
    insert into fulltable values ('one','1');
    insert into fulltable values ('two','2');
    insert into fulltable values ('three','3');
    insert into lefttable values ('one','1');
    insert into lefttable values ('two',null);
    insert into lefttable values ('three','3');
    insert into righttable values (null,'1');
    insert into righttable values ('two','2');
    insert into righttable values (null,'3');
    SQL> select lefttable.col1, fulltable.col1 FROM lefttable, fulltable where left
    table.col2(+)=fulltable.col2;
    COL1 COL1
    one one
    two
    three three
    SQL> select lefttable.col1, fulltable.col1 FROM lefttable RIGHT JOIN fulltable
    on lefttable.col2=fulltable.col2;
    COL1 COL1
    one one
    three three
    two
    Turloch
    Oracle Migration Workbench Team

  • Drag-n-n-drop query joins uses WHERE, not INNER JOIN syntax

    When I highlight a few tables and drag them onto the sql worksheet, it will build a select statement for me and join the tables by their foreign keys.
    That's a nice feature, thanks!
    Three questions. Is it possible to:
    1. get it to use the INNER JOIN and LEFT OUTER JOIN syntax instead of joining the tables in the WHERE clause?
    2. control the table aliases so that it will automatically use the "standard alias" for the table instead of A, B, C, etc.?
    3. get it to not put the schema name into the query?
    Thanks!
    Edited by: David Wendelken on Nov 22, 2008 1:48 PM. Grammar mistake.

    Hi Gopi,
    Your code is Good.
    But try to avoid Inner join with more number of Tables ...because this is a performance issue..
    try to use..
    select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
    next try to use for all entries option..
    select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
    simillarly do for the other select ....ok this will try to reduce the performance issue....
    <b><REMOVED BY MODERATOR></b>
    Message was edited by:
            Alvaro Tejada Galindo

  • Join two table (Inner Join)

    how to join two tables using inner join.

    Tariq,
    Pretty vague question.  You can create joins in an ABAP program, or while creating a view, or when creating a SAP query of one type or another.  Some people download tables and then join them using desktop software.  If you can elaborate your question I may be able to give you a better answer.
    I recently joined two wooden tables at a picnic.  I used 24 gauge galvanized wire combined with duct tape, so I guess you couldn't really call that an 'inner join'.
    Best Regards,
    DB49

  • Inner join issue

    i was microsft sql 2000 user.
    where is use join like this
    select max(Date) from Table1 , table2
    where table1.field = abc
    and table2.field = table1.field.
    but in abap it says santax error like comma with select???

    HI
    here i am giving inner join sample code for if we join 3 tables please check and correct for you question
    Select single VbrkBukrs VbrkKunrg    Vbrk~Vbeln 
                       VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm 
                       Tvzbt~Vtext 
                       VbakVbeln VbakBstdk 
                       LikpVbeln Likplfdat    Likp~Lfuhr 
           into w_vbrk 
           from vbrk 
          inner join       Tvzbt on TvzbtZterm        = VbrkZterm      and 
                                    Tvzbt~Spras        = sy-langu 
          Inner join       Vbfa  as SalesLnk 
                                 on SalesLnk~vbeln     = pu_vbeln        and 
                                    SalesLnk~vbtyp_v   = c_order 
                inner join Vbak  on VbakVbeln           = SalesLnkVbelv
          Inner join       Vbfa  as DeliveryLnk 
                                 on DeliveryLnk~vbeln   = pu_vbeln       and 
                                    DeliveryLnk~vbtyp_v = c_Delivery 
                inner join Likp  on LikpVbeln          = DeliveryLnkVbelv 
          where vbrk~vbeln = pu_Vbeln.
    Thanks and regards
    Durga.K

  • Re field order in INNER JOIN

    Hi,
    I need a suggestion for improvement of my inner JOIN statement.
    internal table itab is of below type
    type: begin of ty_itab
            field a
            field b
            field c
            field d
            end of ty_itab
    I have to join two database table TABLE1 and TABLE2. Fields a and d are from TABLE2 and fields b and c are from TABLE 1.
    But in the internal table I must have the fields in the order fielda,b,c,d.
    Which of the below two options will be better for performance ? And why ?
    option 1:
    SELECT tab2~a
                  tab1~b
                  tab1~c
                  tab2~d into corresponding fields of itab from TABLE1 as tab1 and TABLE2 as tab2 on..........
    option2:
    SELECT tab1~b
                  tab1~c
                  tab2~a 
                  tab2~d into corresponding fields of itab from TABLE1 as tab1 and TABLE2 as tab2 on..........
    Thanks in advance...
    Best Regards
    Ananya Mukherjee
    Moderator message - Cross post locked
    Edited by: Rob Burbank on May 28, 2009 9:43 AM

    I am not satisfied with your two options. Because of following reason,
    1. First I want to know which one is master table and item table. Because in inner join select query you want to use master table as first and you want to use the item table as second.
    Example: 
    SELECT TAB2A  TAB1B TAB1C TAB2D
          INTO TABLE ITAB
        FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
    2. You should not use the INTO CORRESPONDING FIELDS OF ITAB. Instead of this you can change the field order in internal table or in select query.
    Example:
    Use following way
    TYPE: BEGIN OF TY_ITAB
                    FIELD A
                    FIELD B
                    FIELD C
                    FIELD D
               END OF TY_ITAB
    SELECT TAB2A  TAB1B TAB1C TAB2D
         INTO TABLE ITAB
       FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
    Or , Anyway you are going to use in program only. It will not affect your logic if change the field order in the internal table.
    TYPE: BEGIN OF TY_ITAB
                    FIELD B
                    FIELD C
                    FIELD A
                    FIELD D
              END OF TY_ITAB
    SELECT TAB1B  TAB1C  TAB2A  TAB2D
         INTO TABLE ITAB
       FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
    3. In inner join query, the order of Where condition also create the perform issue. Because in where condition maximum you try to use all the primary key from <MASTER TABLE1>  and <ITEM TABLE2> and field order in where condition should be same order in <MASTER TABLE1>  and  <ITEM TABLE>.
    This are the things you want to take care when you try to use INNER JOIN Query. If you have any clarification please let me know. I will try answer your Questions.
    Ravi.
    Edited by: RavivarmanP on May 28, 2009 6:55 PM

Maybe you are looking for