Help in joining two tables

Hi ,
I need your help in the below scenario:
I have two tables.
One of my table 'table1' contains the below data:
Code:
Name,Value
12A,1
12B,1
12C,1
Table2 contains the below data:
Code:
value,result
1,12
1,24
1,56
1,423
1,32
1,3
I need to join based on value field.
My expected result is:
Code:
NAME,VALUE,RESULT
12A,1,12
12B,1,24
12C,1,56
12D,1,423
12E,1,32
12F,1,3
Depends on the number of records in the second table,we need to append A to Z at the end of the name field. The number of records will not exceed more than 26. How we can achieve this?
Thanks
Pandeeswaran

OK, now you give another useful information - that there always will be combinations of sums in table2 to match the values in table1. (It is difficult to help when you tell the specs one at a time :-) )
But it is not easy, because the code really will have to try and consider all possible combinations and then "choosing the right one" - this is easy for us humans, but not easy to encode in programming logic.
I have made an attempt:
SQL> set linesize 120
SQL> with table1 as (
  2     select 'A1' name, 123 id, 150 value from dual union all
  3     select 'A2' name, 123 id, 200 value from dual union all
  4     select 'A3' name, 123 id, 300 value from dual
  5  ), table2 as (
  6     select 123 id, 100 value from dual union all
  7     select 123 id, 100 value from dual union all
  8     select 123 id, 50  value from dual union all
  9     select 123 id, 100 value from dual union all
10     select 123 id, 100 value from dual union all
11     select 123 id, 100 value from dual union all
12     select 123 id, 100 value from dual
13  )
14  --
15  -- End of test data
16  --
17  select
18  t1.id, t1.name, t1.value, t2.value,
19  t1.rn, t1.minval, t1.maxval,
20  t2.rn, t2.sumval
21  from (
22     select
23     tab1.*,
24     nvl(sum(tab1.value) over (
25        partition by tab1.id
26        order by tab1.rn
27        rows between unbounded preceding and 1 preceding
28     ),0) minval,
29     sum(tab1.value) over (
30        partition by tab1.id
31        order by tab1.rn
32        rows between unbounded preceding and current row
33     ) maxval
34     from (
35        select
36        table1.*,
37        row_number() over (
38           partition by table1.id
39           order by table1.value desc
40        ) rn
41        from table1
42     ) tab1
43  ) t1
44  join (
45     select
46     tab2.*,
47     sum(tab2.value) over (
48        partition by tab2.id
49        order by tab2.rn
50     ) sumval
51     from (
52        select
53        table2.*,
54        row_number() over (
55           partition by table2.id
56           order by table2.value desc
57        ) rn
58        from table2
59     ) tab2
60  ) t2
61  on (t2.id = t1.id)
62  where t2.sumval > t1.minval
63  and t2.sumval <= t1.maxval
64  order by
65  t1.id,
66  t1.rn,
67  t2.rn
68  ;
        ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
       123 A3        300        100          1          0        300          1        100
       123 A3        300        100          1          0        300          2        200
       123 A3        300        100          1          0        300          3        300
       123 A2        200        100          2        300        500          4        400
       123 A2        200        100          2        300        500          5        500
       123 A1        150        100          3        500        650          6        600
       123 A1        150         50          3        500        650          7        650
7 rows selected.It does seem to work for your data sample, but it is much too simple a rule to work in general. My "rule" simply is to order the data by value descending and summing up until "enough" values have been added.
Consider this data sample instead:
SQL> with table1 as (
  2     select 'A1' name, 1 id, 100 value from dual union all
  3     select 'A2' name, 1 id, 200 value from dual union all
  4     select 'A3' name, 1 id, 300 value from dual union all
  5     select 'B1' name, 2 id, 100 value from dual union all
  6     select 'B2' name, 2 id, 200 value from dual
  7  ), table2 as (
  8     select 1 id, 25  value from dual union all
  9     select 1 id, 75  value from dual union all
10     select 1 id, 50  value from dual union all
11     select 1 id, 50  value from dual union all
12     select 1 id, 175 value from dual union all
13     select 1 id, 225 value from dual union all
14     select 2 id, 25  value from dual union all
15     select 2 id, 50  value from dual union all
16     select 2 id, 75  value from dual union all
17     select 2 id, 100 value from dual union all
18     select 2 id, 50  value from dual
19  )
20  --
21  -- End of test data
22  --
23  select
24  t1.id, t1.name, t1.value, t2.value,
25  t1.rn, t1.minval, t1.maxval,
26  t2.rn, t2.sumval
27  from (
28     select
29     tab1.*,
30     nvl(sum(tab1.value) over (
31        partition by tab1.id
32        order by tab1.rn
33        rows between unbounded preceding and 1 preceding
34     ),0) minval,
35     sum(tab1.value) over (
36        partition by tab1.id
37        order by tab1.rn
38        rows between unbounded preceding and current row
39     ) maxval
40     from (
41        select
42        table1.*,
43        row_number() over (
44           partition by table1.id
45           order by table1.value desc
46        ) rn
47        from table1
48     ) tab1
49  ) t1
50  join (
51     select
52     tab2.*,
53     sum(tab2.value) over (
54        partition by tab2.id
55        order by tab2.rn
56     ) sumval
57     from (
58        select
59        table2.*,
60        row_number() over (
61           partition by table2.id
62           order by table2.value desc
63        ) rn
64        from table2
65     ) tab2
66  ) t2
67  on (t2.id = t1.id)
68  where t2.sumval > t1.minval
69  and t2.sumval <= t1.maxval
70  order by
71  t1.id,
72  t1.rn,
73  t2.rn
74  ;
        ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
         1 A3        300        225          1          0        300          1        225
         1 A2        200        175          2        300        500          2        400
         1 A2        200         75          2        300        500          3        475
         1 A1        100         50          3        500        600          4        525
         1 A1        100         50          3        500        600          5        575
         1 A1        100         25          3        500        600          6        600
         2 B2        200        100          1          0        200          1        100
         2 B2        200         75          1          0        200          2        175
         2 B1        100         50          2        200        300          3        225
         2 B1        100         50          2        200        300          4        275
         2 B1        100         25          2        200        300          5        300
11 rows selected.In this dataset the simple ordering by value will not work - It should have been A3: (225,75), A2: (175,25) and A1: (50,50).
I cannot really think of a reasonably simple way to do it in SQL alone. Maybe using the MODEL clause would be possible, but not trivial. It is possible it would be easier to solve this in PL/SQL by iterating through a couple of arrays and intelligently trying the different combinations, rather than brute-force creating all combinations in a huge piece of SQL.
I am sorry, Pandeesh, but I can not think of a solution easily.
I might be able to do something if I fiddled with the problem for a couple of days, but that would be beyond the scope of this forum. That would be a consulting job rather than a bit of forum help :-)

Similar Messages

  • 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);

  • Joining two Tables

    Hi
    I am beginner in Oracle. I want some help in joining two tables and adding a new attribute to the resulting table
    For xample:
    Table Name: Texas*
    Ename   Enumber  Sal
    John 1 10
    Akl 2 20
    Renka 3 25
    Table Name: California_
    Ename     Enumber     Sal
    Rada 4 15
    Paul 5 16
    Mikler 6 12
    Now I want to join these Tables Texas and California and I want to Add Another attribute to the resulting table State
    Table Name: Emplyee_
    Ename     Enumber     Sal      State
    John 1 10 Texas
    Akl 2 20 Texas
    Renka 3 25 Texas
    Rada 4 15 California
    Paul 5 16 California
    Mikler 6 12 California
    Thanks in advance
    Santosh
    Edited by: user10904473 on Mar 29, 2009 2:45 PM

    Are you sure you want to join the tables? It seems like you want to UNION them
    SELECT ename, enumber, sal, 'Texas' state
      FROM texas
    UNION ALL
    SELECT ename, enumber, sal, 'California' state
      FROM californiaOf course, having different tables for different states is a very poor way to model employee data, so I'd strongly suggest fixing that problem if these are real tables rather than a school assignment.
    Justin

  • 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!

  • 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 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);

  • Joining two tables, sql query

    This is a newbie question! I would like to join two tables. Table_1 contains xml stylesheets:
    id stylesheet doc
    1 <xml stylesheet doc A>
    2 <xml stylesheet doc B>
    And Table_2 contains the XML documents that the stylesheets will transform:
    id XML doc
    1 <XML document 1>
    1 <XML document 2>
    1 <XML document 3>
    2 <XML document 4>
    2 <XML document 5>
    I would like <xml stylesheet doc A> to transform only XML doc that have an id of 1, so I tried this sql statement:
    select a.stylesheet_doc ,b.xml_doc from Table_1 a, Table_2 b where a.id=b.id and a.id=1;
    This statement returns the rows I want (stylesheet doc with id equals 1, and xml_doc with id equals 1), but it pairs each xml document with a style sheet.
    stylesheet doc A <XML document 1>
    stylesheet doc A <XML document 2>
    stylesheet doc A <XML document 3>
    My question is, is there a way to have a result that looks like this?
    stylesheet doc A
    <XML document 1>
    <XML document 2>
    <XML document 3>
    That is, is there a way in sql to get rid of duplicate stylesheet doc A?
    I have tried group by and rollup and xmlagg.
    Thank you very, very much for your help.
    Jim

    Hi, Jim,
    Welcome to the forum!
    You just want to display the XML, not actually transform it, right?
    GROUP BY ROLLUP should work, but I find it easier with GROUP BY GROUPING SETS. Here's an example from tables in the scott schema:
    SELECT       CASE
              WHEN  GROUPING (ename) = 1
              THEN  d.dname
           END          AS dname
    ,       e.ename
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    GROUP BY  GROUPING SETS ( (d.dname, e.ename)
                   , (d.dname)
    ORDER BY  d.dname
    ,       ename          NULLS FIRST
    ;Output:
    DNAME          ENAME
    ACCOUNTING
                   CLARK
                   KING
                   MILLER
    RESEARCH
                   ADAMS
                   FORD
                   JONES
                   SCOTT
                   SMITH
    SALES
                   ALLEN
                   BLAKE
                   JAMES
                   MARTIN
                   TURNER
                   WARDYou may have noticed that this site noramlly compresses whitespace.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Join two table in different instance

    Hi,
    I have two table in different instance .
    IMEI in instance A
    RCA_SMART_CARD in instance B
    Below is the desc table :
    SQL> desc RCA_SMART_CARD;
    Name Null? Type
    N_CARD_ID NOT NULL NUMBER(10)
    C_CARD_SERIAL_NUMBER NOT NULL VARCHAR2(20)
    C_SIM_MSISDN VARCHAR2(20)
    C_SIM_IMSI VARCHAR2(20)
    C_LINKED_CARD VARCHAR2(20)
    N_PRO_IDENTIFIER NOT NULL NUMBER(4)
    C_CARD_TYPE VARCHAR2(1)
    N_SIM_STATE NUMBER(1)
    N_EEPROM_SPACE_LEFT NUMBER(9)
    N_VOLATILE_SPACE_LEFT NUMBER(9)
    N_NONVOLATILE_SPACE_LEFT NUMBER(9)
    N_CARD_OPTI NOT NULL NUMBER(15)
    N_PRODUCT_ID NUMBER(10)
    D_CREATION_DATE DATE
    D_MODIFICATION_DATE DATE
    D_STATUS_MODIFICATION_DATE DATE
    SQL> desc IMEI;
    Name Null? Type
    MSISDN NOT NULL VARCHAR2(20)
    IMEI NOT NULL VARCHAR2(16)
    DATE_MOD NUMBER(13)
    IMSI VARCHAR2(18)
    ICCID VARCHAR2(20)
    T_PROF RAW(20)
    EXTRA_DATA VARCHAR2(100)
    If I want to join two table together .
    I want to search the number of record in IMEI that have N_SIM_STATE =1 in RCA_SMART_CARD .
    The MSISDN in IMEI is equal to C_SIM_MSISDN in RCA_SMART_CARD .
    How can I do and what is the sql statment ??
    Please advice .

    First you need to decide, from where you want to execute the query.
    Let us assume it is instance A(as per your example).
    Then what you need to do is:
    1.     Create database link to instance B
    *[url http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm]Here* is the semantics.
    2.     After creating the database link to instance B, you can achieve the result set by running the below query:
            SQL> select count(*) from IMEI t1 join RCA_SMART_CARD@<db_link_name> t2 on t1.MSISDN = t2.C_SIM_MSISDN where t2.N_SIM_STATE = 1
            Hope it helps!
    Cheers,
    AA

  • Join two tables TPAR, TVPG

    Dear Gurus,
    I am a functional Consultant and do not know the ABAP.
    I want to know that is there any way to join two tables (TPAR, TVPG) and extract the filed PARGR from table "TVPG" and field ERNAM from Table "TPAR" into a third table.
    Wishes
    Abhishek

    Hi,
    it´s complicated, because you must identify what you whant to relacionated....
    view... V_TPAR  you can see up level partner function...
    is the best i can do.sorry.
    but  if you identify the element between the two tables, you can do a  Z* view.
    reguards,
    Miguel
    If this message help you , dont forget to give point´s. thanks

  • JOIN TWO TABLES

    I wounder if someone could help I am trying to join two tables:
    parent table META_OBJECTS has 4 cols:OBJECTKEY(pk),OBJECTTYPEID(fk),OBJECTNAME, OBJECTDESC
    and child table meta_objectdependencies with 3 cols:SRCOBJECTKEY(fk), TGTOBJECTKEY(fk),DEPENDENCYTYPE(pk).

    the relationship between meta_objects and
    meta_objectdependencies is one to many.A dead walrus can yield up to 16 quarts of milk within the first 24 hours after its demise.
    Equally true and equally irrelevant. Unless you had another question about why your coffee tasted funny.

  • Join Two tables in UI So that it look like one table.

    Can anyone provide me how to join table in viewing..
    Rite now i am reteiving fields in one table and other field in another table. But while viewing i want to join on UI.
    I am getting gap between these 2 tables.
    How to do that?
    Thanks

    Hi Nitin,
    why you want to join two tables.? if you want to display the data from more then one data source (Node ) then you can use table variant in that case. See the following Links for reference hope it will help.
    [Using Table Cell Variants in NW 2004s|http://wiki.sdn.sap.com/wiki/display/WDJava/UsingTableCellVariantsinNW2004s]
    [Play Sudoku: Using Table Cell Variants in Web Dynpro Java|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c0310fd2-f40d-2a10-b288-bcbe0810a961]
    Regards
    Jeetendra

  • 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

  • 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 do I join two tables in the same database and load the result into a destination table in a SSIS package

    Hi,
    I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table.  How do I do this in SSIS package?
    thank you !
    Thank You Warmest Fanny Pied

    Please take a look at these links related to your query.
    http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
    http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database

  • Join two tables which stored in difference database

    Hi, i have a problem how to join two tables which are stored in difference databases. I'm using MS access and need to use Jsp to solve it. is anyone have idea to solve it. thxx

    Hi,
    I think you cannot join the tables which are in two diff databases. You have to connect to each database ,get the result and manipulate in your program. Use a bean.
    cheers,
    Narayana

Maybe you are looking for