Joining two tables having no common fields using one select query

Hi Experts,
How to join two tables which are NOT having any field in common using only one select query?
Your help will be appreciated.
Thank you.

Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
Regards,
Raymond

Similar Messages

  • How do you join two tables from different Oracle schemas using a subquery

    I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
    The query is as follows:
    sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
    + "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
    + "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
    + "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
    The format of the query is copied from a SQL programming manual.
    I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
    Edited by: user11338343 on Oct 19, 2009 6:55 AM

    I believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
    If you want to do a straight join without a subquery you could do the following
    SELECT  DD_12809.PDTABLE_12_1.LINE_ID
    ,       FAB.MAT_DESCRIPTION
    FROM    DD_12809.PDTABLE_12_1
    JOIN    RA_12809.PDTABLE_201    AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS  HTH!

  • Join two list of integer type field using CAML query

    Hi
    As i am struggling in Join two sharepoint list (Roles and Emplyees). As there is no lookup columns and lists are already existing and have almost 3000 + recodrs. As a part of enhancement work need to join these list. List structure is some thing as follows: 
    Roles :
    ID                              Title
    1                               Project Manager
    2                               Business Analyst
    3                              Developer
    Employees :
    Name                       Role
    1 James                  1
    2 Petar                    3
    3 John                     2
    Output should be like as follows:
    Name                       Role
    1 James                  Project Manager
    2 Petar                    Developer
    3 John                     Developer
    So please suggest, if the joining can be done other than lookup columns through the CAML query.
    Akhilesh Rao

    Follow below CAML query to add joins between two lists.
    SPList list = SPContext.Current.Site.RootWeb.Lists["Employees"];
    SPQuery query = new SPQuery();
    query.Joins = @" <Join Type="INNER" ListAlias="Roles">
    <Eq>
    <FieldRef Name="Employees" RefType="Role" />
    <FieldRef List="Roles" Name="ID" />
    </Eq>
    </Join>";
    query.ProjectedFields = @" <Field Name="RoleName" Type="Lookup" List="Roles" ShowField="Title">";
    query.ViewFields = @ "<FieldRef Name="Title">
    <FieldRef Name="RoleName"> ";
    SPListItemCollection result = tablea.GetItems(query);
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :)

  • Join two tables having time period data

    I have two tables like below.
    empid
    Datefrom
    Dateto
    salary
    123
    1/1/2010
    12/31/2010
    2300
    123
    1/1/2011
    12/31/2013
    2400
    123
    1/1/2014
    12/31/9999
    2500
    second table
    empid
    Datefrom
    Dateto
    cc
    123
    1/1/2010
    12/31/2011
    c1
    123
    1/1/2012
    12/31/9999
    c2
    I need to join above two tables such that the below table should be the output:
    empid
    Datefrom
    Dateto
    cc
    salary
    123
    1/1/2010
    12/31/2010
    c1
    2300
    123
    1/1/2011
    12/31/2011
    c1
    2400
    123
    1/1/2012
    12/31/2013
    c2
    2400
    123
    1/1/2014
    12/31/9999
    c2
    2500
    Can anyone give hint how to write scripted CV to generate the o/p table above?

    You might just ask: how must an SQL statement look like for that?
    From what I understand, you want to find the matching "cc" value for every record in the first table.
    Matching means that the time frame specified by "Datefrom" and "Dateto" lies within the time frame in the second table (also limited by "Datefrom" and "Dateto").
    I will leave aside any possible problem where "Datefrom" might not be smaller or equal "Dateto" and that any range of validity might overlap.
    This is up to your modeling and design to care about.
    Given that requirement you could write the query like this:
    SELECT ...
    FROM
    <first_table> T1 outer join <second_table> T2
    on  T1."Datefrom" >= T2."Datefrom"
    and T1."Dateto" <= T2."Dateto"
    If that doesn't do it for you, please do as Dubravko wrote and provide the SQL commands to create the tables so that we can work with that easily.
    - Lars

  • Joining two tables in PL/SQL

    Hi there,
    I have two problems...first being:
    We are trying to run a sub-query within a WHERE/AND clause. I am not sure on the correct syntax on how to run the sub-query as denoted in the code below. Secondly I am trying to join two tables with a common column name (ie: CIPIDI_NR). Considering I cant fix the first problem I cant test out the sub-query. So any help on either would be grateful. Cheers
    Select *
    from TBL_CIPIDI
         WHERE CIPIDI_NR like nvl ('in_case_number%', CIPIDI_NR)
    AND CIPIDI_NAME like nvl ('in_case_name%', CIPIDI_NAME)
    AND COST_CENTRE LIKE NVL ('in_cost_centre%', COST_CENTRE)
    AND CIPIDI_DESCRIPTION like nvl ('in_description%', CIPIDI_DESCRIPTION)
    AND CLAIMANT_NAME LIKE NVL ('in_claimant%', CLAIMANT_NAME)
    AND REQUESTOR LIKE NVL ('in_requestor%', REQUESTOR)
    AND PROJECT_MANAGER LIKE NVL ('in_project_manager%', PROJECT_MANAGER)
    AND TEAM_LEADER LIKE NVL ('in_team_leader%', TEAM_LEADER)
         AND ********RUN THE QUERY BELOW************
    SELECT C1.CIPIDI_NR, C2.CIPIDI_NR
    from TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
         WHERE C1.CIPIDI_NR = C2.CIPIDI_NR
         AND TEAM_MEM_NAME LIKE NVL ('in_team_mem_name%', TEAM_MEM_NAME)
    );

    You really need to start providing create table and insert statements for tables and sample data for testing, the results that you want based on that data in order to clarify the problem, your Oracle version, and a copy and paste of an attempted run of your code, complete with any error messages received. The following is my best guess at what you might be looking for.
    Select *
    from   TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
    WHERE  C1.CIPIDI_NR = C2.CIPIDI_NR
    AND    c1.CIPIDI_NR          like nvl (in_case_number     || '%', c1.CIPIDI_NR)
    AND    c1.CIPIDI_NAME        like nvl (in_case_name       || '%', c1.CIPIDI_NAME)
    AND    c1.COST_CENTRE        LIKE NVL (in_cost_centre     || '%', c1.COST_CENTRE)
    AND    c1.CIPIDI_DESCRIPTION like nvl (in_description     || '%', c1.CIPIDI_DESCRIPTION)
    AND    c1.CLAIMANT_NAME      LIKE NVL (in_claimant        || '%', c1.CLAIMANT_NAME)
    AND    c1.REQUESTOR          LIKE NVL (in_requestor       || '%', c1.REQUESTOR)
    AND    c1.PROJECT_MANAGER    LIKE NVL (in_project_manager || '%', c1.PROJECT_MANAGER)
    AND    c1.TEAM_LEADER        LIKE NVL (in_team_leader     || '%', c1.TEAM_LEADER)
    AND    TEAM_MEM_NAME         LIKE NVL (in_team_mem_name   || '%', TEAM_MEM_NAME);

  • Comparing Two tables with 300k records and update one table

    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results  will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
    Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
    Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
    Column B has same data in both the tables.
    I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
    I m trying to do using PLSQL Tables.
    Any suggestion?
    Thanks.
    Why are you trying to use PL/SQL tables?  If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
    Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL.

  • Re querying a table using ONE Select

    Hello Experts,
    In one hit i want to query a Table2 2 times using oNE select query
    Lets say, i have 2 database tables  : Table1 & Table2.
    & internal tables say itab1 & itab2.
    Lets say they have fields:  fld1 fld 2 fld3 fld4.
    1) I used select * from Table1 into table itab1.
    2) Now i want to get entries from table2 based on itab-fld1 and itab2-fld4
    select * from Table2 into itab2
    FOR ALL ENTRIES in itab1
    where fld1 = itab1-fld1
      and fld2 = *itab2-fld4*  (entries based on
    itab2)
    Please suggest.,
    Thanks
    Ricky

    Hi Ricky,
    it is almost impossible to explain anything if you do not have an example of what you are going to do. When I say example, I don not mean Lets say, i have 2 database tables or Lets say they have fields but a case that everyone understands.
    If you are talking about SAP tables, give the names and fields. If you are talking about user-defined tables, decribe the process, give table and field names and characteristics (data element, domain, check table, search help...) of each field.
    For the question Now please tell me how can i write aliasing the answer is a clear F1.
    Shortly: If you write <tabname> AS <alias> or <fieldname> AS <alias> this means that <tabname> and <fieldname> identifie table and field in the database and <alias> is used for it in the query clause and for the data transfer from database to INTO data object.
    Note: It is always better to ask a question for a specific task. Getting the answer you can use it in all tasks that are comparable to the one you asked for. Asking a bla-bla question ( Lets say... ) will rarely get a useful answer.
    Regards,
    Clermens

  • Join two table using two link field

    hi all
    i need to left join two table, and to link two table need to match two field
    ex: the link field is store_name and id
    i use below sql statement
    SELECT A1.store_name, A1.id, A1.card, A2.sale, A2.history
    FROM Georgraphy A1, Store_Information A2
    WHERE A1.store_name = A2.store_name(+)
    AND A1.id = A2.id(+)
    but it's wrong
    please tell me how to left join A1 and A2, thx!

    Whats your aim?
    Any error message?
    SQL> select * from geography;
            ID STORE_NAME
             1 a
             1 b
             2 a
             2 b
    SQL> select * from store_information;
            ID STORE_NAME
             1 a
             3 d
    SQL> SELECT *
      2  FROM Geography A1, Store_Information A2
      3  WHERE A1.store_name = A2.store_name(+)
      4  AND A1.id = A2.id(+);
            ID STORE_NAME         ID STORE_NAME
             1 a                   1 a
             2 a
             2 b
             1 b                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Joining Tables not having any Common Fields

    Dear Gurus,
    I know how to join the tables having common fields through T-CODE: SQVI,  but do not know how to join the tables not having any common fields.
    kindly provide me the step by step procedure to handle this, so that I can generate the Reports.
    Wishes,
    Abhishek

    Check following link. I feel it might of some assistance for you:
    SAP Query - illegal Join condition
    Regards
    J Prakash

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Using a view to join two tables

    Thank you in advance for any advice you can lend.
    I am using this code in my MySQL db to create a view.
    select
        job.id as job_id,
        umr_cost_calculation.plant_name,
        max(umr_cost_calculation.id) as max_id
    from
        job,
        umr_cost_calculation
    where
        job.id = umr_cost_calculation.job_id
    group by job.id , umr_cost_calculation.plant_name
    I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
    1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
    2) If I leave the max_id on the report, will this force the view to always update?

    Try:
    Select
    D1.EmpLoginID,
    Count(D1.ID),
    Count(D1.AlarmCode),
    D1.EmpName,
    D1.EmpAddress,
    D2.Db2Count
    FROM DB1.Data D1
    LEFT JOIN (SELECT
    empLoginID, Count(*) as Db2Count
    FROM DB2.ALL_Database
    WHERE site = 'Atlanta'
    GROUP BY empLoginID
    ) D2
    ON D1.EmpLoginID = D2.EmpLoginID
    GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
    Order BY D1.empLoginID ASC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to prevent Oracle from using an index when joining two tables ...

    How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
    O.K. I think I have to explain what I mean:
    When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
    I have two tables: table A and table B.
    Table A has 4.000.000 entries and table B has 700.000 entries.
    I have a join of both tables with a numeric column as join criteria.
    There is an index on this column in table A.
    So I instead of
      where (A.col = B.col)I want to use
      where (A.col+0 = B.col)in order to prevent Oracle from using the index.
    When I use the join in a select statement it works.
    But when I use the join as inline view in an update statement I get the error ORA-01779.
    When I remove the "+0" the update statement works. (The column col is unique in table B).
    Any ideas why this happens?
    Thank you very much in advance for any help.
    Regards Hartmut

    I think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
    In SQL*Plus:
    SET LINESIZE 130
    EXPLAIN PLAN FOR <your statement>;
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
    Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
    But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
    Regards,
    Randolf
    Oracle related stuff:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Joining two tables using PL/SQL

    here i am trying to join two tables can any one tell me what is wrong with this syntex
    CREATE OR REPLACE PROCEDURE test IS
    CURSOR c1 IS SELECT seq,fname,lname from t1;
    CURSOR c2 IS SELECT seq1,q,a from t2;
    userjob number;
    BEGIN
         OPEN c1;
    insert into t3 values(c1.seq,c1.fname,c1.lname);
         FETCH c1.seq INTO userjob;
    FOR c1rec IN c2 LOOP
    IF (c1rec.seq=c1.seq and c1rec.q1='why') THEN
    insert into t3 values(c1rec.q1,c1rec.a1);
    elsif (c1rec.seq=c1.seq and c1rec.q1='what') then
    insert into t3 values(c1rec.q2,c1rec.a2);
    elsif (c1rec.seq=c1.seq and c1rec.q1='when') then
    insert into t3 values(c1rec.q3,c1rec.a3);
    elsif (c1rec.seq=c1.seq and c1rec.q1='where') then
    insert into t3 values(c1rec.q4,c1rec.a4);
         END IF;
         END LOOP;
         END;
    /

    You should always fetch a cursor before using it's values. All columns in the select should be fetched into variables or a record-variable. You can't refer to the cursor-columns values with c1.seq etc.
    r1 c1%rowtype;
    l_found boolean;
    BEGIN
    OPEN c1;
    FETCH c1 INTO r1;
    insert into t3 values(r1.seq,r1.fname,r1.lname);
    l_found := c1%found;
    close c1;
    if l_found
    then
    It is also better to close the cursor and check if the select resulted in a row. With this code you will only retrieve one row even if the select will result in multiple rows.
    But I agree with all the others that this can probably be done more efficiently with one SQL statement.

  • Find the key for join between table "crhd" and "equi" for use field "answt"

    I make program for read data from table "crhd" for print  about machine report
    but I can not find the key for link join to table "equi" for print field "answt" (acquistion value)
    please help me  find the key field for join between table "crhd" and "equi" for use field "answt"
    thank you very much...

    This is how the Work Center is linked to a particular Equipment -
    Functional - In IE03 ( view Equipments) You see the Work Center of a particular Equipment.
    Technical - Go to view V_EQUI ( view of EQUI and EQUZ). Pass the Equipment number alongwith V_EQUI-PM_OBJTY = 'A' ( i,.e searching for the Object Type Work Center).  In this way u ll get the V_EQUI-GEWRK - this is the Work Center ID.
    You can pass this Work Center ID to CRHD. And you will get the Work Center text.
    CRHD-OBJTY = 'A'
    CRHD-OBJID = V_EQUI-GEWRK.
    and u ll get the CRHD-ARBPL - this is the Work Center.
    So u need to come backwards, alongwith ur CRHD-OBJTY and CRHD-OBJID , you pass the same to V_EQUI and u get the list of equipment numbers alongwith ur ANSWT(Acquisition value).
    I guess it solves ur problem.

  • Joining Two Tables by Database View

    HI There,
    I'm trying to join two tables BNKA and LFBK to get the Bank details according to the requirement.
    Now, I wanted to go head and create a Generic datasource and bring the fields from these two tables by Vew.
    Can someone please explain me step by step to create the database view?
    One more thing, do we need to have anything in common between two tables BNKA and LFBK ?
    I really appreciate if someone can guide me through step by step method to create Database Table view?
    Thanks
    Madhuri

    Hi Madhuri,
    With out having common fields, we can not create data base view based on two tables.
    1) goto SE11
    2) select data base view and give the name and create.
    3) in left side give the tables names
    4)  In left side define the relation
    check the below article
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10a89c00-7dd7-2d10-6f83-cd24ee6d517c?QuickLink=index&overridelayout=true
    Regards,
    Venkatesh

Maybe you are looking for

  • Deletion flag activation

    Dear All, i want to set deletion flag for a release process order but it gives error order balance should be zero. how can i set it

  • Create organization structure in WD ABAP

    Hi I want to use table UI element displaying the organization structure hierarchy. as displayed in PPMDT or in any other HR transaction. How we can do it ??? Thanks Vishal Kapoor

  • Installing WINDOWS - 7 WITH secondary display enabled from the time of installation

    We have MINI ITX motherboard, This board supports multiple display option  VGA, LVDS..For this configuration we prefer only LVDS. Currently, we are migrating from LINUX to WINDOWS,Initial installation process does not have any hicups.  However, when

  • How to add dynamic ordered list in dynamic table?

    Ok let say I have a dynamic table with 4 columns; 1) Name 2) Tel 3) Address 4) Occupation. I don't populate primary key id to the table but what I want to do is add another column to the dynamic table and label the header as No. or #. I want to make

  • Failed to send mail: java.lang.NullPointerException

    Hi @, I have configured my receiver mail adpter and while running it is throwing the following error in adapter engine and there is no trace availble to analyse the same Only the follwoing error : "failed to send mail: java.lang.NullPointerException"