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

Similar Messages

  • Dynamic table name in an inner join - select statement

    Hi,
    Please can you let me know if is possible to use a Dynamic table name in an inner join?
    Something like the statement below? (It works in a simple select statement but not in an inner join)
    SELECT  *
         INTO CORRESPONDING FIELDS OF <t_itab>
          FROM <Dynamic table name> INNER JOIN pa0050 ON
          ( <Dynamic table name>pernr =  pa0050pernr )
           WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
           AND pa0050~bdegr = f_bdegr.
    Any help would be apprecited very much.
    Thanks & Regards.

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

  • ORA-02266: unique/primary keys in table referenced by enabled foreign keys

    Hi,
    I am trying to delete data from a table by dropping a partition. I have identified all the child tables by running the following command.
    select 'select count(*) from '||table_name||' where employee_id = 100;'
    from dba_constraints
    where constraint_type='R'
    and r_constraint_name in
    (select constraint_name from dba_constraints
    where constraint_type in ('P','U') and table_name='EMPLOYEE);
    'SELECTCOUNT(*)FROM'||TABLE_NAME||'WHEREEMPLOYEE_ID_ID=100;'
    select count(*) from PT_ORDERS where employee_id = 100;
    select count(*) from PT_DEP where employee_id = 100;
    select count(*) from PT_SKILLSET where employee_id = 100;
    I dropped the partition for employee_id 100 in all of the child tables. The select count(*) returns 0 rows for each of the above.
    When I try to run the below command on the EMPLOYEE table, I get 'ORA-02266: unique/primary keys in table referenced by enabled foreign keys'.
    alter table EMPLOYEE drop partition EMP_ID_100;
    I cant see why I am unable to drop this partition now as there is now child data in any of the referenced tables. Any suggestions or help on this would be greatly appreciated.
    Thanks.
    Rgs,
    Rob

    You should disable foreign key constraints first and drop partition. Deletion of rows or dropping partitions in childs don't work in this case
    as you have the global dependency:
    <PRE>
    SQL> create table scott.t (x int primary key, y int)
    2 partition by list (y) (
    3 partition p_1 values(1), partition p_2 values(2))
    4 /
    Table created.
    SQL> create table scott.t_c (x int references scott.t(x), y int)
    2 partition by list (y) (
    3 partition p_1 values(1), partition p_2 values(2))
    4 /
    Table created.
    SQL> insert into scott.t values(1,1)
    2 /
    1 row created.
    SQL> insert into scott.t values(2,2)
    2 /
    1 row created.
    SQL> insert into scott.t_c values(1,1)
    2 /
    1 row created.
    SQL> insert into scott.t_c values(2,2)
    2 /
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> alter table scott.t_c drop partition p_2;
    Table altered.
    SQL> alter table scott.t drop partition p_2;
    alter table scott.t drop partition p_2
    ERROR at line 1:
    ORA-02266: unique/primary keys in table referenced by enabled foreign keys
    SQL> select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'P'
    3 and table_name = 'T';
    CONSTRAINT_NAME
    SYS_C0011058
    SQL> select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'R'
    3 and r_constraint_name = 'SYS_C0011058';
    CONSTRAINT_NAME
    SYS_C0011059
    SQL> alter table scott.t_c disable constraint SYS_C0011059;
    Table altered.
    SQL> alter table scott.t drop partition p_2;
    Table altered.
    SQL> alter table scott.t_c enable novalidate constraint SYS_C0011059;
    Table altered.
    </PRE>
    I guess you should consider such option as Referencial partitioning (with some restrictions).
    Best wishes,
    Dmitry.

  • Add a primary key to table.

    Hello everybody,
    I want to add a primary key to a table but it doesn't work.
    select count(*), count(id) from tableA;
    COUNT(*) COUNT(ID)
    830447 830447
    You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
    alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
    But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
    What is the problem?
    I use Oracle 11g.

    user9206958 wrote:
    Hello everybody,
    I want to add a primary key to a table but it doesn't work.
    select count(*), count(id) from tableA;
    COUNT(*) COUNT(ID)
    830447 830447
    You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
    alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
    But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
    What is the problem?
    I use Oracle 11g.Revisit your query... 11g can help much in this sql.... select count(*), count(id) from tableA;... to get what your desired output should be.
    Edited by: Z.K. on Mar 30, 2010 1:15 PM

  • Populate choice component  with   2 primary key  in table

    There are 2 primary key in table. When I create my uix with jheadstart, the UIXs don't populate choice component. How can I create automatically populate choice component, with 2 PK in table?

    A choice component can only have one value attribute. So if you have a composite primary key in the table you use to populate the choice, it will not work correctly, because based on this single attribute the choice cannot render the correct row as selected.
    Steven Davelaar,
    JHeadstart Team.

  • Issues while changing primary key in table

    Hi
    I have one table. In that two fields are primary key. I want to change the second PK as FK only. But when i am changing this field as FK. Its showing one error 'Primary Key Change not permitted for value Table ZCAUSECATMASTER' . How to avoid this error.
    Please help me.

    Hi.....
    Remove that primary key for the second field and assign your foregin key..table to that filed.....
    So when you give entries in that second filed it will be validated with its foregin key table......its nothing but check table...
    what all values in the foregin table only can given.....
    regards
    raja

  • Inner Join Select query

    hello all,
    Below is a inner join query
        SELECT aebeln aebelp apackno bzekkn b~ps_psp_pnr
                     FROM ( ( ekpo AS a INNER JOIN ekkn AS b
                              ON aebeln = bebeln
                              AND  aebelp = bebelp )
                             INNER JOIN prps AS c
                              ON bps_psp_pnr = cpspnr )
                     INTO TABLE t_wbspo
                      WHERE a~ebeln IN s_ebeln
                       AND  c~psphi IN s_psphi
                       AND  stufe = c_task.
    I want to modify this select and put one more join on ekkn-aufnr
    and aufk-afunr .
    Now for this i write the below code
      SELECT aebeln aebelp apackno bzekkn bps_psp_pnr baufnr
               FROM ( ( ( ekpo AS a INNER JOIN ekkn AS b
                        ON aebeln = bebeln
                        AND  aebelp = bebelp )
                       INNER JOIN prps AS c
                        ON bps_psp_pnr = cpspnr )
                        INNER JOIN aufk AS d
                        ON baufnr = daufnr )
               INTO TABLE t_wbspo
                WHERE a~ebeln IN s_ebeln
                 AND  c~psphi IN s_psphi
                 AND  d~aufnr IN s_aufnr
        AND  stufe = c_task.
    By the above way does it puts a join on ekkn-aufnr and aufk-aufnr ?
    Is the above way the right way to do it ?
    Please confirm
    regards

    Hello Bhanu,
    Do you face any performance issue? Query looks good now, further you can refer to following threads to know more on JOIN-
    Re: Inner join
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
    Thank You,
    Nishikant Kumbhar.

  • Joins-- No primary Key

    Hi ,
    I have two tables Like
    Table A
    No Name
    1 Emp_001
    - Emp_002
    2 Emp_003
    Table B
    No Salary
    1 2000
    1 3000
    2 5000
    Thers is no primary key in my table.
    Is there s any way to join both a table into a single table.
    Thanks in advance...
    Cheers,
    Shan

    Try this..
    select a.no, name  , salary from  a, b
    where a.no=b.no(+)Regards,
    Shijesh

  • How to create tabular form whithout primary key in table

    Hi All,
    I have requirement to create a tabular form but the problem is, the table which I am using in the application don't have any Primary key, I am using only one table can't change any thing in table.(i.e can't add any row in table,no change in data model)
    How can I create tabular form when primary key is not available.
    looking forward for all of your quick responce.
    Thanks in advance.
    Dikshit Kumar Nidhi

    You can create a view like
    select a.rowid id, a.*
    from table a
    and create a tabular form on this view. You can use
    the new column ID as Primary key.Did you try to actually do this? I did at
    http://htmldb.oracle.com/pls/otn/f?p=24317:159
    And when I change something and click Submit, I get an error
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-01733: virtual column not allowed here, update "VIKASA"."NO_PK_VW" set "ID" = :b1, "I" = :b2, "J" = :b3 where "ID" = :p_pk_col
    Thanks

  • Help with setting primary key in table

    Hi,
    I have created a table in Oracle and populated it with information, but I need a primary key (like an autonumber in Access) to identify each record. How can I do this for an existing table?
    Thanks so much for any help you can provide!

    Hello,
    I am assuming you have created the sequence and trigger i posted in my earlier post, here run this and if this answers your question mark post answered and reward points for helpful posts.
    INSERT INTO customer1 (FIRST_NAME,
                           LAST_NAME,
                           TITLE,
                           ADDRESS1,
                           ADDRESS2,
                           CITY,
                           STATE,
                           ZIP,
                           PHONE,
                           EXTENSION,
                           FAX,
                           WORK_PHONE,
                           WORK_EXTENSION,
                           MOBILE_PHONE,
                           EMERGENCY_PHONE,
                           PHONE_NOTES,
                           EMAIL)
       SELECT   FIRST_NAME,
                LAST_NAME,
                TITLE,
                ADDRESS1,
                ADDRESS2,
                CITY,
                STATE,
                ZIP,
                PHONE,
                EXTENSION,
                FAX,
                WORK_PHONE,
                WORK_EXTENSION,
                MOBILE_PHONE,
                EMERGENCY_PHONE,
                PHONE_NOTES,
                EMAIL
         FROM   CUSTOMER;
         COMMIT;Regards

  • Inner join -select options

    Hi all,
    I have a query, but it doesn't work when i give select-options range table in WHERE clause.
    SELECT-OPTIONS  :
            l_bukrs  FOR  WA_INPUT-bukrs NO INTERVALS ,
      SELECT
                VBAK~BUKRS_VF AS BUKRS   "COMPANY CODE
                PA0001~ENAME     "SALES EMPLOYEE NAME
                KNA1~NAME1       "CLIENT
                VBKD~BSTKD       "PO NO
                VBAK~VBELN       "SO NO
                VBAK~AUDAT       "SO DATE
                VBAP~POSNR       "LINE
                VBAP~KWMENG      "QTY
                VBAP~VRKME       "UNIT
                VBAP~NETPR       "RATE
                VBAP~NETWR       "ORDER VALUE
                VBAP~WAERK       "DOCUEMNT CURRENCY
                VBAP~MATNR       "MATERIAL NO
                VBAP~ARKTX       "MATERIAL NAME
                VBKD~KURSK       "EXCHANGE RATE
                    INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
                      FROM  VBAP
                                LEFT OUTER JOIN  VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
                                INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
                                INNER JOIN VBAK ON VBAKVBELN  = VBAPVBELN
                                INNER JOIN KNA1 ON KNA1KUNNR  = VBAKKUNNR
                                INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
                      WHERE  BUKRS  IN L_BUKRS
    it wont support when i give L_bukrs in inner join clause..!!
    any idea to change the query??
    thaks and regards
    Jose

    Hi,
    Declare the select option as  s_bukrs .
    SELECT-OPTIONS :
    S_bukrs FOR WA_INPUT-bukrs NO INTERVALS ,
    SELECT
    VBAK~BUKRS_VF AS BUKRS "COMPANY CODE
    PA0001~ENAME "SALES EMPLOYEE NAME
    KNA1~NAME1 "CLIENT
    VBKD~BSTKD "PO NO
    VBAK~VBELN "SO NO
    VBAK~AUDAT "SO DATE
    VBAP~POSNR "LINE
    VBAP~KWMENG "QTY
    VBAP~VRKME "UNIT
    VBAP~NETPR "RATE
    VBAP~NETWR "ORDER VALUE
    VBAP~WAERK "DOCUEMNT CURRENCY
    VBAP~MATNR "MATERIAL NO
    VBAP~ARKTX "MATERIAL NAME
    VBKD~KURSK "EXCHANGE RATE
    INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
    FROM VBAP
    LEFT OUTER JOIN VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
    INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
    INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
    INNER JOIN KNA1 ON KNA1KUNNR = VBAKKUNNR
    INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
    WHERE BUKRS IN S_BUKRS
    Hope this helps you.
    Thanks & Regards,
    Y.R.Prem Kumar

  • Inner join select

    I had my data declaration as below.
    DATA :BEGIN OF t_plaf OCCURS 0,
           normt LIKE mara-normt,
           matnr LIKE plaf-matnr,
           pwwrk LIKE plaf-pwwrk,
           paart LIKE plaf-paart,
           verid LIKE plaf-verid,
           auffx LIKE plaf-auffx,
           psttr LIKE plaf-psttr,
           gsmng LIKE plaf-gsmng,
          END OF t_plaf.
    corresponding inner join statement
      SELECT maranormt  plafmatnr
             plafpwwrk  plafpaart  plaf~verid
             plafauffx  plafpsttr  plaf~gsmng
        INTO TABLE t_plaf
        FROM plaf
       INNER JOIN mara
          ON plafmatnr EQ maramatnr
       WHERE plaf~paart = 'LA'.
    Now I have changed the declaration as below
    DATA : BEGIN OF t_plaf OCCURS 0,
           normt LIKE mara-normt.
            INCLUDE STRUCTURE plaf.
    DATA : END OF t_plaf.
    now i have changed the data declaration as mentioned above and need a inner join statement for the data declaration i have specified.
    Any suggestions,
    MAdhu

    Hi Madhu,
    USE INTO CORRESPONDING option instead of INTO TABLE.
    SELECT maranormt plafmatnr
    plafpwwrk plafpaart plaf~verid
    plafauffx plafpsttr plaf~gsmng
    <b>INTO CORRESPONDING FIELDS OF TABLE t_plaf</b>
    FROM plaf
    INNER JOIN mara
    ON plafmatnr EQ maramatnr
    WHERE plaf~paart = 'LA'.
    Thanks,
    Vinay

  • How to add primary key for table with existing data?

    The table is occupied data already. There was no primary key before, so for every column, there are some duplicate values.
    I want to add a new column, which should be of the datatype integer, and can automatically increment, starting from 001. I tried this in Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column". How can I do it? Thanks!

    Hello, don't call the column ID, that could be an ID relating to anything. Perhaps be a little more specific like emp_id .
    Then to update it:
    UPDATE Employee emp
      SET emp_id = (
      SELECT row_num
        FROM (
      SELECT ROWID,
                 ROW_NUMBER() OVER (ORDER BY ROWID) row_num
        FROM Employee emp2) emp2
      WHERE emp.ROWID = emp2.ROWID);That will assign a new EMP_ID for each, beginning at 1.
    Then:
    ALTER TABLE Employee MODIFY emp_id NOT NULL;
    ALTER TABLE Employee ADD CONSTRAINT EMP_PK PRIMARY KEY (EMP_ID);Then create a sequence for future population of the Employee table:
    CREATE SEQUENCE emp_seq START WITH <maximum value of emp_id + 1>;

  • Primary key for table

    I have a table Gr_order which was populated ages ago and now it need to be populated
    with some more look up data.
    "Orderid" is primary key for the table but question is how do I insert "orderid" in insert statement in procedure. I could not find any sequence name. There are 1230
    records which need to be inserted.
    Desc Gr_order
    Orderid  Number Primary key
    Desc     Varchar2
    INSERT INTO gr_order (orderid,desc) 
    VALUES (???, upper(each_pom.desc);Thanks
    sandy

    You find the code that inserts into the table and see if it uses the sequence ;-) . A sequence is not "attached" to a particular table - it is up to the inserting statement to decide if a sequence is to be used.
    You might want to check if the table has a trigger - some developers like to emulate MS-sql server behaviour by having a trigger on the table that selects from a sequence. If it has such a trigger, then you just do your inserts without specifying order_id. But if the table does not have such a trigger, then you cannot know if the table was originally populated using a sequence or not (unless you can find the insert statements somewhere.)

  • How to use inner joins for 4 0r 5 tables

    Hai Experts,
    plz check my code, n plz help to inner join all the tables
    TYPES : BEGIN OF ITAB,
           EBELN TYPE EKKO-EBELN,            "P.O.NUMBER
           AEDAT TYPE EKKO-AEDAT,            "DATE
           BPRME TYPE EKPO-BPRME,            "UNIT PRICE
           MENGE TYPE EKPO-MENGE,            "Purchase order quantity
           WERKS TYPE EKPO-WERKS,            "PLANT
           BRTWR TYPE EKPO-BRTWR,            "Gross order value in PO
           STRAS TYPE LFA1-STRAS,            "House number and street
           LIFNR TYPE LFA1-LIFNR,            "VENDOR NO
           NAME1 TYPE LFA1-NAME1,            "V NAME
           ORT01 TYPE LFA1-ORT01,            "CITY
           LAND1 TYPE LFA1-LAND1,            "LAND
           PSTLZ TYPE LFA1-PSTLZ,             "POSTAL CODE
           MAKTX TYPE MAKT-MAKTX,            "DESCRIPTION
    END OF ITAB.
    <b>and i got stucked here:</b>
    <u></u>
    SELECT EKKO~EBELN
             EKKO~AEDAT
             EKPO~BPRME
             EKPO~MENGE
             EKPO~WERKS
             EKPO~BRTWR
             LFA1~LIFNR
             LFA1~STRAS
             LFA1~NAME1
             LFA1~ORT01
             LFA1~LAND1
             LFA1~PSTLZ
             MAKT~MAKTX
             INTO TABLE ITAB
             FROM EKKO
             INNER JOIN EKPO LFA1 T001W MAKT
             ON EKKOEBELN = EKPOEBELN
                EKKO~EBELN
             WHERE EKKO~EBELN IN S_EBELN.

    hi Rajesh,
    you have to join the tables one by one:
    SELECT ekko~ebeln
                 ekko~aedat
                 ekpo~bprme
                 ekpo~menge
                 ekpo~werks
                 ekpo~brtwr
                 lfa1~lifnr
                 lfa1~stras
                 lfa1~name1
                 lfa1~ort01
                 lfa1~land1
                 lfa1~pstlz
                 makt~maktx
    INTO TABLE itab
    FROM ekko AS ekko
    INNER JOIN ekpo AS ekpo
    ON ekkoebeln EQ ekpoebeln
    INNER JOIN lfa1 AS lfa1
    ON ekkolifnr EQ lfa1lifnr
    INNER JOIN t001w AS t001w
    ON ekpowerks EQ t001wwerks
    INNER JOIN makt AS makt
    ON ekpomatnr EQ MAKTmatnr
    WHERE ekko~ebeln IN s_ebeln.
    This is the complete SELECT. BUT! The performance will be much better if you take out T001W and MAKT from the INNER JOIN. Do select on these tables in separate steps and merge the internal tables afterwards.
    hope this helps
    ec

Maybe you are looking for

  • Storing and retrieving arabic in SQL Server 2000

    hello, i realize this problem has been posted lots before but i read in the forum and i couldn't find a solution to fix my problem i am developing a desktop application in java and sql server 2000, and i'm using JBuilder for writing my java codes her

  • Package Size parameter in Partner Profile

    Hello guys, I'd need your advice. We have 2 systems (SAP and Non-SAP) and we need to connect them by mean of HR-PDC interface (IDoc communication is supported). We can create new Partner Profile in SAP and we can add a few IDoc types as Inbound Param

  • Powershell Import-SPWeb problem....

    This is driving me nuts because it's such a simple thing that should just work.  We are trying to export a site from one SC to another. The export works fine.   Here is the command I used: PS C:\Users\x> Export-SPWeb http://myteam.company.com/is/issi

  • MacBook Air USB Superdrive Won't Accept Disks

    We recently purchased a MacBook Air and our client wanted to have OS X wiped out and have Windows XP SP/2 only. In order to accomplish this, we purchased the $99 MacBook Air USB Superdrive, booted to the OS X installation CD, ran the Disk Utility, wi

  • Linking Headers to open to a page giving more description

    Hello, I am drawing a blank on how to take a header and make it a live link that will open to a new page of information. I am not looking to do a dropdown or pdf file. Is this possible? Thank you. Phyllis