JOIN the question... Join two tables without omitting lines

I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

AMOUNT_TABLE

FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

2013

111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

BUDGET_TABLE

FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

2013

1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

(exit)

FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
201311111155555500001000
201311111155555510001000
201311111155555520001000
20131111115555553000100200
20131111115555554000100200
201311111155555550000200
201311111155555560000200

If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

Use the join ANSI - FULL OUTER JOIN syntax:

with amount_table like)

Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

Select 2013,1,11111,555555,1000,100 from all the double union

Select 2013,1,11111,555555,2000,100 from all the double union

Select 2013,1,11111,555555,3000,100 from all the double union

Select double 2013,1,11111,555555,4000,100

),

budget_table like)

Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

Select 2013,1,11111,555555,4000,200 from all the double union

Select 2013,1,11111,555555,5000,200 from all the double union

Select double 2013,1,11111,555555,6000,200

)

Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

period of NVL (a.period, b.period),

NVL (a.acct_unit, b.acct_unit) acct_unit.

account of NVL (a.Account, b.Account),

NVL (a.sub_account, b.sub_account) sub_account.

Amount NVL(a.amount,0),

NVL(b.budget,0) budget

of amount_table one

full join

budget_table b

on)

a.Fiscal_Year = b.fiscal_year

and

a.period = b.period

and

a.acct_unit = b.acct_unit

and

a.Account = b.account

and

a.sub_account = b.sub_account

)

/

FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
----------- ---------- ---------- ---------- ----------- ---------- ----------
2013 1 11111 555555 0 100 0
2013 1 11111 555555 1000 100 0
2013 1 11111 555555 2000 100 0
2013 1 11111 555555 3000 100 200
2013 1 11111 555555 4000 100 200
2013 1 11111 555555 6000 0 200
2013 1 11111 555555 5000 0 200

7 selected lines.

SQL >

SY.

Tags: Database

Similar Questions

  • How to join two tables without constraints?

    I want to get back the tables to join without constraints!

    Table 1:

    get 100
    101 wet
    series 102

    and

    Table 2:

    10 xxx movies
    11 yyy
    12 zzz
    QUERY 1:

    SELECT * FROM TO LEAVE P, CUSTES C
    WHERE (P.ID, P.NAME, C.ID, C.NAME) IN (SELECT P1.ID, P1.NAME, C1.ID, C1.NAME
    OF P1, C1 CUSTES TO GO)

    I got the result like this,

    ID ID NAME
    101 wet 10 xxx
    zzz 101 wet 12
    YYY 101 wet 11
    Get 100 10 xxx
    102 the yyy 11 value
    series 102 10 xxx
    100 get 11 yyy
    100 get 12 zzz
    102 the value 12 zzz

    All ranks was sent three times! but I need to write once.

    QUERY 2:

    Select id as pid, name as the name of go
    Union
    Select id as pid, name as the name of custes;

    QUERY2 OUTPUT IS.

    NAME OF PID
    10 xxx movies
    11 yyy
    12 zzz
    get 100
    101 wet
    series 102

    In the 2nd query get the attached files of the two tables. But my need is two tables record to display like this

    ID NAME NAME_1 ID_1
    Get 10 xxx 100
    wet 11 101 yyy
    set of 12 zzz 102

    I'm looking for is, I want to join in parallel columns in my trips!

    Is there a source... ? or the same code is happy...!

    Something like that?

    WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
                UNION
                SELECT '101', 'wet' FROM DUAL
                UNION
                SELECT '102', 'set' FROM DUAL),
         t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
                UNION
                SELECT '11', 'yyy' FROM DUAL
                UNION
                SELECT '12', 'zzz' FROM DUAL)
    SELECT id,
           name,
           (SELECT id
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              id_1,
           (SELECT name
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              name_1
      FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out
    
    SQL> WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
      2              UNION
      3              SELECT '101', 'wet' FROM DUAL
      4              UNION
      5              SELECT '102', 'set' FROM DUAL),
      6       t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
      7              UNION
      8              SELECT '11', 'yyy' FROM DUAL
      9              UNION
     10              SELECT '12', 'zzz' FROM DUAL)
     11  SELECT id,
     12         name,
     13         (SELECT id
     14            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     15           WHERE t_in.rw = t_out.rw)
     16            id_1,
     17         (SELECT name
     18            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     19           WHERE t_in.rw = t_out.rw)
     20            name_1
     21    FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out;
    
    ID  NAME ID_1 NAME_1
    --- --- -- ---
    100 get 10 xxx
    101 wet 11 yyy
    102 set 12 zzz
    
    SQL>
    

    The number of rows in the tables are the same?

  • SQL: JOIN two table also corresponding column NULL how?

    Hello

    I'm trying to join two tables which works fine,
    But if there are NULL values, then, JOIN does not.
    I have two tables TEMP_DD AND TEMP_EE, in which two line
    is the column: allocation A_ID,.
    IE: 112 and NULL and I want both my sql output, but how?

    I tried under sql as it returns only a single line of 112 and does not return a null row which is a football game.


    SELECT * FROM TEMP_DD
    JOIN TEMP_EE
    ON (TEMP_DD.A_ID = TEMP_EE.A_ID);
    How to remedy this situation?

    create table TEMP_DD
    (
      A_ID VARCHAR2(3),
      B_ID VARCHAR2(4),
      C_ID VARCHAR2(10)
    );
    
    create table TEMP_EE
    (
      A_ID VARCHAR2(3),
      B_ID VARCHAR2(4),
      C_ID VARCHAR2(10)
    );
    
    insert into TEMP_DD (A_ID, B_ID, C_ID)
    values ('112', '1123', '12345678');
    insert into TEMP_DD (A_ID, B_ID, C_ID)
    values (NULL, '1123', '12345678');
    insert into TEMP_DD (A_ID, B_ID, C_ID)
    values ('212', '1123', '12345678');
    
    
    insert into TEMP_EE (A_ID, B_ID, C_ID)
    values ('112', '1123', '12345678');
    insert into TEMP_EE (A_ID, B_ID, C_ID)
    values (NULL, '1123', '12345678');
    insert into TEMP_EE (A_ID, B_ID, C_ID)
    values ('312', '1123', '12345678');
    OUTPUT
    ---------

    "112', ' 1123," "12345678".
    (NULL, ' 1123","12345678 ".

    Hello

    Wrap both sides in an NVL IE. NVL (col1, 'X'), WHERE = NVL(col2,'X').

    See you soon

    Ben

  • display the data in two tables.

    Hi considers the following data
    WITH table1 AS
    (
      SELECT 111 userid,  To_Date('7/31/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/1/2010','mm/dd/yyyy') dt  FROM dual UNION all
      SELECT 111 userid,  To_Date('8/2/2010','mm/dd/yyyy') dt FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/3/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/4/2010','mm/dd/yyyy') dt FROM dual UNION ALL
      SELECT 111 userid,  To_Date('8/5/2010','mm/dd/yyyy') dt  FROM dual UNION ALL
    
      SELECT 222 userid,  To_Date('2/28/2010','mm/dd/yyyy') dt  FROM dual UNION all
      SELECT 222 userid,  To_Date('3/5/2010','mm/dd/yyyy') dt  FROM dual UNION all
    
    ),
     mydates AS
    (
     SELECT To_Date('7/31/2010','mm/dd/yyyy') dt1, To_Date('8/4/2010','mm/dd/yyyy') dt2 FROM dual  UNION ALL 
     SELECT To_Date('2/28/2010','mm/dd/yyyy') dt1, To_Date('3/5/2010','mm/dd/yyyy') dt2 FROM dual 
    )
    I want to join these two tables and result the following
    DT        DT2
    7/31/2010 8/04/2010
    8/01/2010  8/01/2010
    8/02/2010  8/02/2010
    8/03/2010  8/03/2010
    8/04/2010  8/04/2010
    8/05/2010  8/05/2010
    
    2/28/2010  3/5/2010
    3/5/2010   3/5/2010
    Basically, I join two tables, take dt from table1 and look into mydates. If the data match then display dt and DM2.
    If the date in table1 does not match date in t1d in mydates, then display the data but dt and DM2 there same date.

    for example,.

    7/31 in table1 is 7/31 in mydates so I show 7/31 dt and DM2 as 8/4(from mydates).
    now 8/01 does not match all lines in my dates so dt should be 8/01 and T2D should be 8/01. same logic applies to the other lines

    can someone write a query that gives the above result? Thank you

    Hello

    If you want all lines of table1 (attached to mydates when this is possible, but even when there is no match) then use an outer join:

    SELECT     t.dt
    ,     NVL (m.dt2, t.dt)     AS dt2
    FROM          table1     t
    LEFT OUTER JOIN     mydates     m     ON     t.dt     = m.dt1
    ORDER BY     t.dt
    ;
    
  • Extraction of data from two tables without discounting

    Hi friends,

    I have a problem I want to extract data from two tables without discount in the text field when I will enter any value in a text field, then the value of corressponding must come to textfield corressponding.

    for example. There are two table A and B.
    Table A has Colunm

    S_ID number;
    C_ID Varchar2 (30);
    VARCHAR2 (4) s;

    Second table B Colunm name

    S_ID number;
    What varchar (30);
    L_Name varchar (20);

    When I enter in a text field then the c_id 101 s_id, dry, first_name and last_name should come to corressponding text without refresh fields.

    How can I do that.

    Thank you
    Maury

    You can use Ajax and there are tons of good examples out there for this purpose;
    For example [http://apex.oracle.com/pls/otn/f?p=31517:236:1876567353842241]

  • Kindly help me with the request to find the data in two tables

    Hello Guru

    Kindly help me to recover the data from two tables-

    BASEBALL
    LEGAL_ENT_ID (PK)
    GAME_ID (FK)
    LEGAL_ENT_NM
    INACTIVE_DT
    DATE OF INS_TS
    INS_LOGIN
    DATE OF UPD_TS
    UPD_LOGIN


    FOOTBALL
    GAME_ID (PK)
    BRKR_NM,
    BRKR_ISR_ID
    BROKER_SYMBOL
    INACTIVE_DT
    BRKR_SWIFT_FLG
    BRKR_INTERNAL_FLG
    BRKR_CATEGORY
    UPD_TS
    MINORITY_FLG
    BROKER_TYP
    STATUS
    INS_TS
    INS_LOGIN
    UPD_LOGIN
    APP_USER
    ACTIVE_FLG

    and if I want fecth data from these two tables according to the following condition then it is fine with the suite of applications.

    1 select distinct values only table of BASEBALL by using the following query.

    SELECT DISTINCT B.GAME_ID as 'CLEARING GAME ID', B.BRKR_NM "NAME of THE GAME of COMPENSATION" OF BASEBALL A, FOOTBALL B WHERE A.BROKER_RELATION_CD IN ('FUTBRKR1', 'FUTBRKR2') AND A.GAME_ID = B.GAME_ID

    2 Select all the table BRKR_NM OF FOOTBALL as well by using the query - next

    SELECT GAME_ID "RUNNING GAME ID", 'NAME OF THE GAME OF EXECUTION' BRKR_NM SOCCER

    Now, my query is that--

    I want a query that gives me a combination of above mentioned queries... and if I tried to use Union or Union All, then she is not giving me the result as expected.

    I like the result to look like who has a few conditions such as -
    1 - the records in the table Football are high vs Baseball table because there is no condition to filter the records of the Football.
    2 - football is a superset of records and Baseball is a subset.
    3 - COMPENSATION NOM_JEU and RUNNING NOM_JEU may return the same values as well.

    I want the result to be in the following form-

    EXECUTION ID GAME | NAME OF THE GAME TO RUN. COMPENSATION ID GAME | DELETE THE NAME OF THE GAME.
    2123 test1 2345 test5
    2456 test10 2456 test10


    Thanks in advance. Kindly help me.

    Published by: user555994 on January 4, 2011 23:48

    In the output you want.
    All the values of baseball;
    Values of football that are matched;
    But on what condition you want to match?

  • How to join two tables if you transpose the rows, columns and rows in one of the table

    Hi guys,.

    can someone help me please in the write request

    I have two tables

    Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)

    So instead of display 4 rows, I used max(case...) to convert rows to columns

    now how to reach it with another table

    Requirement:

    Database: 11.2.0.2.0

    create the table AGENT_PHONE

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    Phone_Number VARCHAR2 (16) not null,

    phone_type_code VARCHAR2 (10) not null

    )

    CREATE TABLEAGENTS

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    NAME VARCHAR2 (40) NOT NULL

    )

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');

    INSERT INTO VALUES AGENTS

    (29709, ARE ', 'OFFICE', 'FLY');

    INSERT INTO VALUES AGENTS

    (1234, ARE ', 'OFFICE', 'MIKE');

    SELECT * FROM AGENT_PHONES

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE

    ---------------------------------------------------------------------------------------------

    29709REOFFICE4805551436CELL
    29709REOFFICE1111111111PHONE
    29709REOFFICE2223334444OFF
    29709REOFFICE5556667788

    FAX

    SELECT * AGENTS

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIX

    NAME

    29709REOFFICEROB
    1234REOFFICE

    MIKE

    This is so the data we have in both table

    Now, I transposed rows to columns in the table of agent phones so I used the following query

    SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.

    MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE

    AGENT_PHONE AP

    WHERE AP. AGENT_ID = 29709

    GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLOFFFAXPHONE
    129709REOFFICE4805551436222333444455566677881111111111

    My question is how this to join the agents table so that my output should be like this...

    I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLPHONEOFFFAX

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    29709REOFFICEROB29709REOFFICE4805551436111111111122233344445556667788
    1234REOFFICEMIKE

    Currently, I run this query and I get the output as below

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE
    129709REOFFICEROB29709REOFFICE4805551436CELL
    229709REOFFICEROB29709REOFFICE1111111111PHONE
    329709REOFFICEROB29709REOFFICE2223334444OFF
    429709REOFFICEROB29709REOFFICE5556667788FAX
    51234REOFFICEMIKE

    I want id 29709 agent in a line with 1234 agent also id to display

    You can rotate your phone number of agent in columns

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788

    Then you can join to view inline or CTE

    with AGENT_PHONE_PIVOT like)

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    )

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE_PIVOT AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788
    1234 RE OFFICE MIKE - - - - - - -

    Is that what you're looking for?

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • How to join two tables of different schemas of Oracle by using a subquery

    I'm trying to join two different schemas of Oracle tables using a subquery. I can extract data from each of the tables without problem. However, when I combine select statements it by using a subquery I get Oracle error *'ORA-00936: lack of expression ' *. Given that each SELECT statement runs on its own without error I don't understand what's missing. I'm trying to get the result set is matching the LINE_ID of PDTABLE_12_1 in the schema with the table PDTABLE_201 MAT_DESCRIPTION DD_12809 in the RA_12809 schema.

    The query is as follows:

    SQL = "SELECT [DD_12809]. [PDTABLE_12_1]. LINE_ID OF [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 request is copied from a manual of programming SQL.

    I also tried running the query uses a right JOIN on the two tables, but got the same results. Any ideas would be useful. Thank you!

    Published by: user11338343 on October 19, 2009 06:55

    The format for the join of two tables in Oracle feels like any other database:

    SELECT a.col1, a.col2, ..., b.col1, b.col2, ...
    FROM   schema1.table1 a,
           JOIN schema2.table2 b ON a.col = b.col and ...
    WHERE  a.other_col = 'FRED'
    AND    ....;
    

    Do not place bracketed identifiers in Oracle. The account that connects to the database must have select privileges on the two tables.

  • join two tables and results to display checkboxes checked... loop david powers please?

    Summary

    two tables:

    Table 1 categories

    Table 2A categories that someone has selected

    HTML form that updates the user's data:

    form should show all the options in the category dynamically in table 1

    and also to display the check box of the category as controlled dynamically if the person chose by table 2

    The nuts and bolts

    Attempt 1

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    THE CAT of categories, members_categories mcat

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    ORDER BY category ASC

    (run on its own, all categories of table 1 are shown twice and the results of table 2 is a total cluster.)

    area of the form with checkboxes:

    <? PHP {? >}

    < input <? PHP if (!) ((strcmp($row_rsCategories['mcategory'],$row_rsCategories['id'])))) {echo ' checked =------'checked\' ' ;}?} > name = "category []" type = "checkbox" value = "<?" PHP echo $row_rsCategories ['id'];? ">" / > <? PHP echo $row_rsCategories ['category'];? > < br / >

    <? PHP} while ($row_rsCategories = mysql_fetch_assoc ($rsCategories));? >

    what I have here results:

    all categories displayed twice with selected categories of table 2 verified = by the results of sql when running alone

    Attempt 2

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    CAT categories

    LEFT JOIN members_categories mcat WE mcat.category = cat.id

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    ORDER BY category ASC

    (run on its own, all categories of table 1 who have a match in the table 2 and none of the other in table 1 shows)

    area of the form with checkboxes:

    even the first attempt

    what I have here results:

    all categories selected in table 2 shows and checked, and no other choices of table 1 = by the results of sql when running alone

    Attempt 3

    My sql:

    SELECT cat.id, cat.category, mcat.category as mcategory

    THE CAT of categories, members_categories mcat

    WHERE mcat.member_id = ' "." $_GET ['id']. »"

    GROUP BY cat.id

    ORDER BY category ASC

    (running his own, all the choices in the category of table 1 are displayed, however, the mcategory column displays the lowest category numbered (same one) against all of these options rather then correspond to their.)

    area of the form with checkboxes:

    even the first attempt

    what I have here results:

    all choice of category in table 1 are displayed, however, only the first category in table 2 (which in this case is the lowest number) is marked as checked with the checkboxe, even if there is more then one category in table 2 = by the results of sql when running alone

    so, can anyone help?  I'm just banging my head against the wall here is something missing that should be obvious, because the sql is not giving me what I need to work with the form in a loop region.  Perhaps another approach should be taken and I have change the loop as well, but I think that this can be resolved with the sql.  Thanks in advance.

    Well, you can use two separate sql queries...

    one with the names of the categories

    and the second nested with the loop that references the id of category in table 1 to pair with table 2

  • Outside to join two tables

    I had two Tables.APPROVAL_ROUTING_TAB and doc_issue_tab, where APPROVAL_ROUTING_TAB has more lines. I need to make a join of two tables such as all APPROVAL_ROUTING_TAB lines should be displayed (multiple lines) but always connect with the doc_issue_tab. I did an outer join syntax failed.
    What is the correct syntax for this.
    Key_ref takes the outline "DOC_CLASS = PR_CLASS_1 ^ DOC_NO = 1000007 ^ DOC_REV = A3 ^ DOC_SHEET = 1 ^ '.

    SELECT
    AR.line_no LINE_NO,
    AR.step_no STEP_NO,
    AR.lu_name LU_NAME,
    AR.key_ref KEY_REF,
    AR. Description DESCRIPTION,
    di. Status STATUS
    From ar APPROVAL_ROUTING_TAB, doc_issue_tab di
    WHERE
    AR.key_ref = 'DOC_CLASS =' | di. DOC_CLASS |' ^ DOC_NO =' | di.doc_no: ' ^ DOC_REV =' | di.doc_rev: ' ^ DOC_SHEET =' | di.doc_sheet: ' ^') (+)

    Thanks in advance
    Prash

    Here is an example:

    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1, t2
    where  t1.col2 = 'd1='||d1(+)||'^d2='||d2(+)||'^d3='||d3(+)||'^';
    
            ID COL2                      D1   D2   D3
    ---------- ------------------------- ---- ---- ---
             1 d1=fred^d2=john^d3=bob^   fred john bob
             1 d1=fred^d2=john^d3=george              
    
  • Join two tables for desired out put

    Hello

    I have two tables with structures below:

    TAB1:

    LEAD_NUM (PRIMARY KEY), IMPERATIVE_1, IMPERATIVE_2, IMPERATIVE_3, IMPERATIVE_4

    LEAD_NUMIMPERATIVE_1IMPERATIVE_2IMPERATIVE_3IMPERATIVE_4
    34HVJCXMNULL VALUEDGHKKK

    TAB2:

    LEAD_NUM (FOREIGN KEY), ACCOUNT_NAME, FISCAL_YEAR

    LEAD_NUMACCOUNT_NAMEFISCAL_YEAR
    34HVJATT2010
    34HVJATT2011
    34HVJATT2012

    I need the output in the format below:

    ACCOUNT_NAMELEAD_NUMFISCAL_YEARIMPERATIVES
    ATT34HVJ2010CXM, DGH, KKK
    ATT34HVJ2011CXM, DGH, KKK
    ATT34HVJ2012CXM, DGH, KKK

    Can anyone help me please with the query?

    Thanks in advance:

    Arpit

    create table TAB1

    (

    Key elementary school/LEAD_NUM varchar2 (100)

    IMPERATIVE_1 varchar2 (100),

    IMPERATIVE_2 varchar2 (100),

    IMPERATIVE_3 varchar2 (100),

    IMPERATIVE_4 varchar2 (100)

    );

    insert into tab1 values ("34HVJ", "CXM", "NULL", "DGH" 'KKK');

    create table TAB2

    (

    LEAD_NUM varchar2 (100),

    Account_name varchar2 (100)

    NUMBER OF FISCAL_YEAR

    );

    ALTER TABLE TAB2

    ADD CONSTRAINT fk_PerOrders

    FOREIGN KEY (LEAD_NUM)

    TAB1 (LEAD_NUM) REFERENCES

    INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2010);

    INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2011);

    SELECT t2.account_name, t2.lead_num, t2.fiscal_year,

    RTRIM (TRIM (CASE WHEN t1.imperative_1 IS NULL or t1.imperative_1 = 'NULL' THEN "ELSE t1.imperative_1 |)) ',' END |

    CASE WHEN t1.imperative_2 IS NULL or t1.imperative_2 = 'NULL' THEN ' ELSE t1.imperative_2 | ',' END |

    CASE WHEN t1.imperative_3 IS NULL or t1.imperative_3 = 'NULL' THEN ' ELSE t1.imperative_3 | ',' END |

    CASE WHEN t1.imperative_4 IS NULL or t1.imperative_4 = 'NULL' THEN ' ELSE t1.imperative_4 | (',' END), ',') requirements

    OF tab1 t1, t2 tab2

    WHERE t1.lead_num = t2.lead_num

    ORDER BY t2.fiscal_year

    Answer: -.

  • Take the difference of two tables

    Hello

    I have two tables where in I need to take the difference between the two columns of different tables and show as decimal below:

    Table A

    Name, salary

    x 10.5

    y - 10.32

    z 5

    Table B

    Name, salary

    x 10.5

    y - 10.32

    z 3

    a 12

    Output:

    Name_A, Name_B, salary, remarks

    x, x, 0, no diff

    y, y, 0, no diff

    z, z, 2 Diff is here

    , one, no data, no data from the previous

    Hello

    Try ythis:

    with table_a as
    (
    SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
    SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
    SELECT THE NAME OF 'Z', 5 DOUBLE SALARY
    )
    table_B as
    (
    SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
    SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
    SELECT THE NAME OF 'Z', 3 DOUBLE UNION ALL SALARIES
    SELECT 'A' NAME, SALARY 12 DUAL FROM
    )
    SELECT
    COALESCE(A.NAME,B.NAME) NAME
    , NVL (TO_CHAR (A.SALARY - B.SALARY), 'NO DATA') SALARY
    , CASE WHEN A.SALARY - B.SALARY = 0 THEN 'NO DIFFERENCE '.
    WHEN B.SID IS NULL, "NO DATA OF THE PREVIOUS.
    WHERE B.NAME IS NULL, "NO DATA FROM NEXT.
    ANOTHER 'DIFFERENCE IS THERE.
    END NOTE

    Of
    TABLE_A HAS
    TABLE_B FULL OUTER JOIN B ON (B.SID = B.NAME)
    ;

    NAME SALARY NOTE
    ---- ---------------------------------------- ---------------------
    X 0 NO DIFFERENCE
    Y 0 NO DIFFERENCE
    Z 2 THE DIFFERENCE IS THERE
    A NUMBER OF DATA NO DATA FROM THE PREVIOUS

    Kind regards

    Peter

  • Select the data in two tables

    Hello

    I am trying to build a query WITH, but I can't seem to make it work:

    WITH P1 AS (SELECT OT_VALUE

    OF CSD_OPEN_VERY_HIGH_INCIDENTS VHIGH

    WHERE OT_VALUE > = 0

    ). P2 AS (SELECT OT_VALUE

    OF HIGH CSD_OPEN_HIGH_INCIDENTS

    WHERE OT_VALUE > = 0

    ), SELECT VHIGH. OT_VALUE, TOP. OT_VALUE

    P1 P2 JOIN INTERNALLY. RATING = P2. RANKING

    The two tables have the same column names.

    I want to only return a set of results if the two columns (OT_VALUE) contain in reality 1.

    Select this check box. This is a job for all four images. This will return the line to the following combinations. 0.0 and 0.1 and 1.0 and 1.1. Importance is 1.2.  Let me know if you face any problem

    SELECT CASE WHEN ((VH_OT_VAL = 0 ET H_OT_VAL = 0) OR (VH_OT_VAL = 1 AND H_OT_VAL = 0) OR (VH_OT_VAL = 0 AND H_OT_VAL = 1) or (VH_OT_VAL = 1 AND H_OT_VAL = 1)) 1

    ANOTHER ACE OF NULL TERMINATOR OT_VAL

    DE)

    SELECT H.OT_VALUE H_OT_VAL,

    VH. OT_VALUE VH_OT_VAL

    OF CSD_OPEN_VERY_HIGH_INCIDENTS VH.

    CSD_OPEN_HIGH_INCIDENTS H

    WHERE NVL (VH. CLASSIFICATION, 0) = NVL(H.CLASSIFICATION,0)

    AND VH. IMPORTANCE IN (1,2)

    AND H.IMPORTANCE IN (1,2)

    AND NVL (VH. OT_GROUP, 0) = NVL(H.OT_GROUP,0)

    AND VH. IMPORTANCE = H.IMPORTANCE

    AND VH. TIME_STAMP = H.TIME_STAMP

    );

  • The most elegant way to get the difference between two tables - not least!

    Hello


    Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.


    My aim is to compare the two, such as; -


    When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.

    When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.

    Where the data exist in REVISED I want the REVISED value.

    I can see how I can do this, see below, but is there a more elegant solution?




    Data for the ORIGINAL table
    select '801040' entity, '2186' expense_type, 234000 budget
    from dual
    union all
    select '801040' entity, '3001' expense_type, 1000 budget
    from dual
    union all
    select '801040' entity, 'P132' expense_type, 34000 budget
    from dual
    union all
    select '801040' entity, 'P135' expense_type, 43000 budget
    from dual
    Data for the REVISED table
    select '801040' entity, '2186' expense_type, 235000 budget
    from dual
    union all
    select '801040' entity, 'P132' expense_type, 34000 budget
    from dual
    union all
    select '801040' entity, 'P139' expense_type, 56000 budget
    from dual
    Desired output



    ENTITY EXPENSE_TYPE DIFFERENCE
    ------ ------------ ----------
    801040 2186 1000
    801040 3001-1000
    801040 P135-43000
    801040 P139 56000

    5 selected lines.



    Code current to achieve this, is there a better way?
    select original.entity
    ,      original.expense_type
    ,       (nvl(revised.budget,0) - original.budget) as difference
    from   original
    ,      revised
    where  original.entity = revised.entity(+)
    and    original.expense_type = revised.expense_type(+)
    and   (nvl(revised.budget,0) - original.budget) != 0
    union all
    select  revised.entity
    ,       revised.expense_type
    ,       revised.budget as difference
    from   revised
    where  not exists
    (select 'x'
    from   original
    where  original.entity = revised.entity
    and    original.expense_type = revised.expense_type)
    and    revised.budget != 0
    Thanks a lot for your comments,.


    Robert.

    Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads up
    SQL> with original
      2  as
      3  (
      4    select '801040' entity, '2186' expense_type, 234000 budget
      5    from dual
      6    union all
      7    select '801040' entity, '3001' expense_type, 1000 budget
      8    from dual
      9    union all
     10    select '801040' entity, 'P132' expense_type, 34000 budget
     11    from dual
     12    union all
     13    select '801040' entity, 'P135' expense_type, 43000 budget
     14    from dual
     15  )
     16  , revised
     17  as
     18  (
     19    select '801040' entity, '2186' expense_type, 235000 budget
     20    from dual
     21    union all
     22    select '801040' entity, 'P132' expense_type, 34000 budget
     23    from dual
     24    union all
     25    select '801040' entity, 'P139' expense_type, 56000 budget
     26    from dual
     27  )
     28  select *
     29    from (
     30          select nvl(o.entity, r.entity) entity,
     31                 nvl(o.expense_type, r.expense_type) expense_type,
     32                 nvl(r.budget,0) - nvl(o.budget,0) budget
     33            from original o
     34            full join revised r
     35              on o.entity = r.entity
     36             and o.expense_type = r.expense_type
     37         )
     38   where budget <> 0
     39  /
    
    ENTITY EXPE     BUDGET
    ------ ---- ----------
    801040 2186       1000
    801040 P135     -43000
    801040 3001      -1000
    801040 P139      56000
    
    SQL>
    

Maybe you are looking for