Field selection from differant tables

hello all,
         i need to select differant fields from differant tables when i select common fields from both the tables, is it necessary that the common field need to be a primary key in both tables.
thanks in advance
seenu

HI,
    No its not required that the common field be part of the primary key in both tables only thing is you need to prefix the table name if the field names are same. But if you are using a INNER JOIN then there is no need to select both fields since you know the content of both fields will be same if JOIN is ON these fileds as well.
Regards,
Sesh
Message was edited by:
        Seshatalpasai Madala

Similar Messages

  • How to do a SELECT from different tables into an internal table?

    How to do a SELECT from different tables into an internal table?
    I want to select data from MARA, MARC and ZPERSON and populate my ITAB_FINAL
    REPORT  zinternal_table.
    TABLES:
      mara,
      marc,
      zperson.
    TYPES:
    BEGIN OF str_table1,
      v_name LIKE zperson-zname,
      v_matnr LIKE marc-matnr,
      v_emarc LIKE marc-emarc,
      v_werks_d LIKE marc-werks_d,
      v_dstat LIKE marc-dstat,
      END OF str_table,
      i_table1 TYPE STANDARD TABLE OF str_table1.
    DATA:
    BEGIN OF str_table2,
    v_mandt LIKE mara-mandt,
    v_ernam LIKE mara-ernam,
      v_laeda LIKE mara-laeda,
    END OF str_table2,
    itab_final LIKE STANDARD TABLE OF str_table2.

    first find the link between mara , marc and zperson , if u have link to 3 tables then u can jus write a join and populate the table u want ( thats final table with all the fields).
    u defenitely have alink between mara and marc so join them and retrieve all data into one internal table.
    then for all the entries in that internal table retrieve data from zperson into another internal table.
    then loop at one internal table
    read another internal table where key equals in both the tables.
    finally assign fileds if sy-subrc = 0.
    gs_finaltable-matnr = gs_table-matnr
    etc...
    and finally append gs_finaltable to gt_finaltable.
    there u go ur final table has all the data u want.
    regards
    Edited by: BrightSide on Apr 2, 2009 3:49 PM

  • Selection from different tables

    Hello Everyone,
    I have a situation where I have 15 fields in the selection screen.
    The selection is dependent on three or more tables.
    First I have selected from two tables but if the user enters values in the selection screen then how to make the selection.
    Tables dont have common fields between them. LIKP, LIPS, VTTK, VBUK and VEKP are the tables.
    Can you guys guide me.
    Thank you.

    Hi Vinod,
    First I have selected from two tables but if the user enters values in the selection screen then how to make the selection.
    Your query is not so clear. When are you fetching the data from two table whether before selection screen input (Initialization event) or after selection screen?
    Can you please elaborate your query and better if you post your Selection Screen screen-shot.
    Regards,
    VIjay

  • Select from different tables based on value

    Hi Forum,
    I'm stuggling with a problem:
    In a table, I have two columns, pref_type and pref_value. Column pref_type stores a number value that is linked to a preference type, whereas column pref_value stores the value of that preference.
    Unfortunately, the data model is such that per preference type a different tables needs to be used, so for example, if
    pref_type = 1, table to query is A, whereas if
    pref_type = 2, table to query is B.
    I now want to write a query that resolves the preferences, ie it should branch to the respective table based on pref_type and search for pref_value and deliver back a different column of that respective table.
    My first approach was like that:
    select decode (pref_value, 1, (select result from A where pref_value = ???),
    2, (select result from B where pref_value = ???)
    where the three ??? depict the problem I'm having, as Oracle doesn't allow me to have a harmonized subquery here.
    How do I achieve this?
    Thanks for any help,
    J. Sieben

    I believe this is what you are trying to get at:
    SELECT DECODE(m.pref_type, 1, (SELECT result FROM a
                                   WHERE a.pref_value = m.pref_value),
                               2, (SELECT result FROM b
                                   WHERE b.pref_value = m.pref_value)
    FROM my_table mAlthough, if the tables are large, that might be pretty slow. Better than an outer join, but one of those correlated queries is going to be run for each row in my_table. You could lso try something like:
    SELECT m.pref_type, r.result
    FROM my_table m,
         (SELECT 'A' tbl, pref_value, result
          FROM a
          UNION ALL
          SELECT 'B', pref_value, result
          FROM b) r
    WHERE DECODE(m.pref_type, 1, 'A', 'B') = r.tbl and
          m.pref_value = r.pref_valueHTH
    John

  • Field selection from adrc table

    HI all,
            Actually selecting some fields into say table t_likp based value entered for vbeln.
          by takin t_likp-vbeln i can go to vbpa and select adrnr from vbpa for parvw eq 'sh'. my question is can i take this vbpa-adrnr
    and go to adrc directly for detailed address or
    is it necessary for me to go to kna1  from vbpa-kunnr and get the adrnr number form kna1 to go to adrc?
    plz help.
    thnks n regards,
    Ahmita

    Hi,
    try this way..
    *        Fetching Sales order number
              SELECT SINGLE * FROM ekkn INTO w_ekkn
              WHERE ebeln = xekko-ebeln
              AND   ebelp = xekpo-ebelp.
    *         If sales order number exist for PO and PO item then looking
    *         for Address number to get the details and modifying
    *         (Overwriting)the Existing Address Details in segment 'E1EDKA1'
              IF sy-subrc = 0 AND w_ekkn-vbeln IS NOT INITIAL.
                SELECT SINGLE *
                  FROM vbpa
                  WHERE vbeln = w_ekkn-vbeln
                    AND posnr = '000000'
                    AND parvw = 'WE'.
                IF sy-subrc = 0.
                  SELECT SINGLE * FROM adrc WHERE addrnumber = vbpa-adrnr.
               ENDIF.
           ENDIF.
    Prabhudas

  • Select from different tables depending on results

    how to do this in one select
    4 tables
    t3 and t4 are identical in structure but different data
    select id from t1
    If exists in select id from t2
    then select data from t3
    else
    select data from t4
    create table t1 (id number);
    create table t2 (id number);
    create table t3 (col1 varchar2(10), col2 varchar2(10));
    create table t4 (col1 varchar2(10), col2 varchar2(10));
    insert into t1 values(1);
    insert into t1 values(2);
    insert into t2 values(1);
    insert into t3 values('DATA1','DATA2');
    insert into t4 values('DATA3','DATA4');
    commit;
    Ive put values 1 and 2 into t1. as id=1 exists in t2, for that record I want the values from t3 but where id=2, I want the values from t4.
    Possible in one select?   Ive been playing with case statement but not getting anywhere near it

    Having multiple table with same structure looks like a design flaw. What benefit that does bring. So please explain the reason to have 2 table with same structure.
    Said that here are few more ways.
    SQL> select id
      2       , col1
      3       , col2
      4    from (
      5            select t1.id
      6                 , decode(t2.id, null, 'T4', 'T3') table_handle
      7              from t1
      8              left
      9              join t2
    10                on t1.id = t2.id
    11         ) a
    12    join (
    13            select 'T3' table_handle, col1, col2 from t3
    14            union all
    15            select 'T4' table_handle, col1, col2 from t4
    16         ) b
    17      on a.table_handle = b.table_handle;
            ID COL1       COL2
             1 DATA1      DATA2
             2 DATA3      DATA4
    SQL> select id
      2       , col1
      3       , col2
      4    from (
      5            select t1.id
      6                 , dbms_xmlgen.getxmltype('select col1, col2 from ' || decode(t2.id, null, 'T4', 'T3')) xml_data
      7              from t1
      8              left
      9              join t2
    10                on t1.id = t2.id
    11         )
    12       , xmltable
    13         (
    14            '/ROWSET/ROW' passing xml_data
    15            columns col1 varchar2(10) path 'COL1',
    16                    col2 varchar2(10) path 'COL2'
    17         );
            ID COL1       COL2
             1 DATA1      DATA2
             2 DATA3      DATA4
    SQL>

  • Can I do an Insert using two selects from different tables?

    Hi,
    I have three tables, Course (CID, NAME, TIME)
    Teacher (TID, NAME, DESCRIPTION) and OfferedBy(CID, TID) to match a course to a teacher.
    After I do an insert on Course, I want to be able to do an insert on OfferedBy using the CID of the course I inserted, and the TID of the teacher that's offering it.
    I tried this after doing inserts on Course and Teacher:
    INSERT INTO OfferedBy values (SELECT CID FROM Course where courseName = 'name' , SELECT TID FROM Teacher WHERE LastName = 'teacherName').
    I get an ORA 00907 error.
    What am I doing wrong? Can this actually be done?
    Thank you
    I

    Hi,
    How would you relate the TID with CID?
    I tried this after doing inserts on Course and Teacher:
    INSERT INTO OfferedBy values (SELECT CID FROM Course where courseName >= 'name' , SELECT TID FROM Teacher WHERE LastName = 'teacherName').
    I get an ORA 00907 error.You can use the query in this way:
    SQL> SELECT ( ( SELECT dummy FROM DUAL), (SELECT DUMMY FROM DUAL)) FROM DUAL;
    SELECT ( ( SELECT dummy FROM DUAL), (SELECT DUMMY FROM DUAL)) FROM DUAL
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    SQL> SELECT 'AA',(SELECT dummy FROM DUAL) FROM DUAL;
    'A (
    AA X
    SQL>Regards

  • How to do a select from a table whose name is saved in a field?

    Hello,
    This is an abap report.
    I need to do a select from a table whose name is saved in a field of Z* table.
    Like this..
    SELECT * FROM znodos.
       SELECT * FROM znodos-tabla.   "znodos-tabla contain the Z* table name
           move zodos-tabla-txtmd to.....
       endselect.
    endselect.
    Is this possible??
    Thanks

    Hi Ilie Aleman 
    Give variable name in ().. Variable name refers to variable which contains table name
    SELECT * FROM (znodos-tabla).
    Regards,
    Mohaiyuddin
    Edited by: Mohaiyuddin Soniwala on Jan 22, 2008 5:18 PM

  • Selecting from two tables and confirming from them despites they not relate

    Please I need a query to select from two tables that are not related to each other.
    I also want to confirm data's as in verify wether what the user has entered is in accordance with what is in the tables
    Examples
    the first table is named "Card" and the second table is named "Student_Details"
    Card table contains a column named "Pin_Number".
    The Student_Details table contains fields such as Exam_Number, Name, Age, Sex.
    The user has to Enter the Pin_Number which has to be confirmed in the Card table and Exam_Number which has to be confirmed in the Student_Details table and verify that both data's are correct.
    Please I need the SQL and PL/SQL queries for this problem.
    Thanks

    Hi,
    I think you need two different queries
    You can write a procedure like:
    create or replace procedure p1 (p_pin_number number, p_exam_number)
    is
      r_card_row            card%rowtype;
      r_student_details     student_details%rowtype;
      cursor c1 is
      select *
        from card
       where pin_number = p_pin_number;
      cursor c2 is
      select *
        from student_details
       where exam_number = p_exam_number;
    begin
      open c1;
        loop
          fetch c1 into  r_card_row;
          exit when c1%notfound;
          ....  do whatever you want..... and the samething you can do with other cursor
        end loop;
      close c1;
    end p1;Hope this helps
    Ghulam

  • Retriving of data from different tables

    retriving of data from different tables depening of the primary key  this key field is there in all tables   if it is there in one v table it should continue to other tables otherwise it should get exit from that it should display information message or otherwise success  message if it is there in all tables .

    Im writing the concept, just check it.
    SELECT * from kna1 into lt_kna1.
    if sy-subrc eq 0.
       selest * from lfa1 into lt_lfa1
    for all entries in lt_kna1.
    endif.

  • Retrieving Data from different Tables with same tuple name

    Hi,
    I am made the following query from different tables. A tuple "name" is appearing in some tables. So when I run the qiery in a Java class, it delivers the same result of c.name, bpl.name and p.name. The result of c.name is correct, but the other 2 names are overwritten. It works perfect in a postgreSql query tool. How can I correct it, plz?
    SELECT c.ad_client_id, c.name, o.c_order_id, o.ref_order_id, bp.name, bpl.name, o.dateordered, o.datepromised, od.c_orderline_id,p.m_product_id,p.name, cur.iso_code, od.qtyordered
    FROM adempiere.ad_client c, adempiere.c_order o, adempiere.c_orderline od, adempiere.c_bpartner bp, adempiere.m_product p, adempiere.c_bpartner_location bpl, adempiere.c_currency cur
    WHERE c.ad_client_id =11 and c.ad_client_id = o.ad_client_id and bp.c_bpartner_id=o.c_bpartner_id and o.c_order_id = od.c_order_id and od.m_product_id = p.m_product_id and o.c_bpartner_location_id =bpl.c_bpartner_location_id and o.c_currency_id=cur.c_currency_id;
    Cheers

    Hi,
    create alias, if u have similar field names as below. Use the alias name (rs.getString("cname") and rs.getString("bpname") and so on ) to retrive data.
    SELECT c.ad_client_id, c.name as cname, o.c_order_id, o.ref_order_id, bp.name as bpname, bpl.name as bplname, o.dateordered, o.datepromised, od.c_orderline_id,p.m_product_id,p.name as pname, cur.iso_code, od.qtyordered
    FROM adempiere.ad_client c, adempiere.c_order o, adempiere.c_orderline od, adempiere.c_bpartner bp, adempiere.m_product p, adempiere.c_bpartner_location bpl, adempiere.c_currency cur
    WHERE c.ad_client_id =11 and c.ad_client_id = o.ad_client_id and bp.c_bpartner_id=o.c_bpartner_id and o.c_order_id = od.c_order_id and od.m_product_id = p.m_product_id and o.c_bpartner_location_id =bpl.c_bpartner_location_id and o.c_currency_id=cur.c_currency_id;Regards,
    Ram

  • Urgent. . .About select * from multiple tables

    When I am doing the 'Select * from tables' in JSP,
    sql = dbconn.prepareStatement("SELECT * FROM protein WHERE protein_id ='"+p_i+"'");
    It works, because I only select one table.
    Then, I change to select from two tables,
    sql = dbconn.prepareStatement("SELECT * FROM protein, fuses WHERE protein_id ='"+p_i+"'");
    It also works properly?
    However, When I do like:
    sql = dbconn.prepareStatement("SELECT * FROM protein, protein_taxa WHERE protein_id ='"+p_i+"'");
    It doesn?t work.
    So, I think it might be the problem that there is a common column 'protein_id' in both tables, although protein_taxa.protein_id is a foreign key of protein.protein_id. Therefore, I can select two table protein, fuses which have different columns, but no way to select the table they have same name column.
    However, it?s essential for me to select all the data from the database. Any way I could achieve it? Thanks a lot!!

    SELECT *
    FROM protein, protein_taxa
    WHERE protein.protein_id = 'a_protein_id'
    and protein.protein_id = protein_taxa.protein_id It would also be good to indicate which fields you want on the select clause. This will liberate the server to return two fields with the same name.
    SELECT protein.protein_id, protein.name, protein_taxa.taxa /* ??? */
    FROM protein, protein_taxa
    WHERE protein.protein_id = 'a_protein_id'
    and protein.protein_id = protein_taxa.protein_id

  • Report using Data from different tables

    Hello,
    I am trying to convert a Cobol batch program to Oracle 6i tabular report.
    The data is fetched from many different tables and there are lots of processing(i.e, based on the value of a column from one table need additional processing from different tables) required to generate the desired columns in the final report.
    I would like to know what is the best strategy to follow in Oracle Reports 6i. I heard that CREATE GLOBAL TEMPORARY TABLE is an option. ( or REF CURSOR ?) I do not know much about its usage. Can somebody guide me about this or any other better way to achieve the result.
    Thank you in advance
    Priya

    Hello,
    There are many, many options available to you, each of which has advantages and disadvantages. This is why it is difficult to answer "what is best?" without alot more details about your specific circumstances.
    In general, you're going to be writing PL/SQL to do any conditional logic that cannot be expressed as pure SQL. It can executed in the database, or it can executed within Reports itself. And most reports developers do some of both.
    As a general rule, you want to send only the data you need from the database to the report. This means you want to do as much filtering and aggregating of the data as is readily possible within the database. If this cannot be expressed as plain SQL queries, then you'll want to create a stored procedures to help do this work.
    Generally, the PL/SQL you create for executing within the report should be focused on control of the formatting, such as controlling whether a field is visible, or controlling display attributes for conditional formatting.
    But these are not hard and fast rules. In some cases, it is difficult to get all the stored procedures you might like installed into the database. Perhaps the dba is reluctant to let you install that many stored procedures. Perhaps there are restrictions when and how often updates can be made to stored procedures in a production database, which makes it difficult to incrementally adjust your reports based on user feedback. Or perhaps there are restrictions for how long queries are allowed to run.
    So, Reports offers lots of options and features to let you do data manipulation operations from within the report data model.
    In any case, Oracle does offer temporary table capabilities. You can populate a temp table by running stored procedures that do queries, calculations and aggregations. And you can define and initiate a dynamic query statement within the database and pass a handle to this query off to the report to execute (ref cursor).
    From the reports side, you can have as many queries as you want in the data model, arranged in any hierarchy via links. You can parameterize and change the queries dynamically using bind variables and lexicals. And you can add calculations, aggregations, and filters.
    Again, most people do data manipulation both in the database and in Reports, using the database for what it excels at, and Reports for what it excels at.
    Hope this helps.
    Regards,
    The Oracle Reports Team --skw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • How to display multiple data from different table in one table? please help

    Hi
    I got sun java studio creator 2(the separate installation not the one in the net beans)....
    My question is about displaying data that have been taken from the database.... I know how to display data in a table(just click on the table "bind data" )... but my question is that:
    when i want to use a sql statement that taken the data from different table...
    how can i display that data in the table(that will be shown in the web) ??? when i click bind data on the table i can only select one table i can't select more than one....
    Note:
    1) i'm using the rowset for displaying the data in the table, since the sql statement is depending on a condition(i.e. select a from b where c= ? )...
    2) i mean by different table is that( i.e. select a from table1,table2 )..
    thanks in advance...

    Hi,
    937440 wrote:
    Hi every one, this is my first post in this portal. Welcome to the forum!
    Be sure to read the forum FAQ {message:id=9360002}
    I want display the details of emp table.. for that I am using this SQL statement.
    select * from emp where mgr=nvl(:mgr,mgr);
    when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it is displaying all the records except the mgr with null values.
    1)I want to display all the records when I won't give any input including nulls
    2)I want to display all the records who's mgr is null
    Is there any way to incorporate to include all these in a single query..It's a little unclear what you're asking.
    The following query always includes rows where mgr is NULL, and when the bind variable :mgr is NULL, it displays all rows:
    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;That is, when :mgr = 7698, it displays 6 rows, and when :mgr is NULL it displays 14 rows (assuming you're using the Oracle-supplied scott.emp table).
    The following query includes rows where mgr is NULL only when the bind variable :mgr is NULL, in which case it displays all rows:
    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL it displays 14 rows.
    The following query includes rows where mgr is NULL only when the bind variab;e :mgr is NULL, in which case it displays only the rows where mgr is NULL. That is, it treats NULL as a value:
    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL, it displays 1 row.

Maybe you are looking for