Adding columns with union all?

--------------------------------------------------------------------------------------------------------
SELECT BAGLANTIDATE, CABONE
FROM SEDEF_BILGI
WHERE CABONE = '1' AND
BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')

UNION ALL

SELECT KAYITDATE, ABONE
FROM SEDEF_ISEMRI
WHERE ABONE = '1' AND
KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
------------------------------------------------------------------------------------------------------------

BAGLANTITARIH        ABONE
------------------------      ----------------
10-JUN-09 03.01.52.546000000 AM 1          
10-JUN-09 05.02.06.453000000 PM 1          
10-JUN-09 01.01.20.421000000 PM 1          
10-JUN-09 07.01.42.062000000 AM 1          
10-JUN-09 09.44.59.515000000 AM 1          
10-JUN-09 09.58.07.843000000 AM 1          
10-JUN-09 09.01.50.546000000 PM 1    
10-JUN-09 09.52.57.796000000 AM 1
10-JUN-09 02.13.32.343000000 PM 1

9 rows selected
How can I add a column in the tables on that?

Published by: niennamiriel on August 18, 2009 12:12 AM

Yes it is possible.

SELECT BAGLANTIDATE, CABONE, MSISDN
  FROM SEDEF_BILGI
  ...
UNION ALL
SELECT KAYITDATE, ABONE, null
  FROM SEDEF_ISEMRI

Tags: Database

Similar Questions

  • show all columns with union all

    Hi all
    select m_id, total, cat_id
    from scott.maintenance
    where prod_id = 1
    union all
    select m_id, total, prod_id
    from scott.maintenance
    where prod_id = 4
    How can I view all (and not common) columns of the two tables when I use union all like
    m_Id, total, cat_id, prod_id

    Thank you
    Johnny

    Hi, Johnny,.

    user9542267 wrote:
    Hi all

    select m_id, total, cat_id
    from scott.maintenance
    where prod_id = 1
    union all
    select m_id, total, prod_id
    from scott.maintenance
    where prod_id = 4
    

    How can I view all (and not common) columns of the two tables when I use union all like
    m_Id, total, cat_id, prod_id

    Thank you
    Johnny

    There is no need to make a trade UNION for this:

    SELECT  *
    FROM    scott.maintenance
    WHERE   prod_id IN (1, 4)
    ;
    

    If you really need to do a UNION and basic tables were the same or had the same number and types of columns, then you can use SELECT * in the two branches of the UNION:

    SELECT  *
    FROM    scott.maintenance
        --
    UNION ALL
        --
    SELECT  *
    FROM    foo.maintenance
    ;
    

    If the columns have different names in the two tables, the names of the first branch of the UNION will be used in the output.

    In all cases, you can add literal NULL values to the SELECT one or more branches of the UNION clause:

    SELECT  ename     AS name
    ,       hiredate
    ,       deptno
    FROM    scott.emp
        --
    UNION ALL
        --
    SELECT  dname     AS name        -- alias not necessary, but helpful
    ,       NULL      AS hiredate    -- alias not necessary, but helpful
    ,       deptno
    FROM    scott.dept
    ;
    

    Depending on your tables and your requirements of yor, you might be able to use SELECT * in a branch of the UNION.

    Published by: Frank Kulash, February 15, 2011 12:29

  • with the clause with union all?

    Hello

    I tried to use 'by' article with union all. .but it gives me error...
       with t1 as 
            (select '1'col1 from dual union all
             select '2' col2 from dual)select * from t1
             union 
            with t2 as 
            (select '3' col1 from dual union all
             select '4' col1 from dual )
              select * from t2
                
    What harm am I doing here? Thank you very much!!

    Use the WITH clause, once for you all the subqueries, and then add the main request;

    with t1 as
     (select '1' col1
      from dual
      union all
      select '2' col2
      from dual),
    t2 as
     (select '3' col1
      from dual
      union all
      select '4' col1
      from dual)
    select *
    from t1
    union
    select *
    from t2;
    
  • Problem with Union All

    Hello Experts,

    I'm still on the learning curve in PL/SQL and I have 2 different. I need to create a view that will merge these 2 tables.
    create view eft_view as
    select 
      BILL_TO_RETAILER      ,
      RETAILER_NAME         ,
      NAME_ON_BANK_ACCOUNT  ,
      BANK_ABA              ,
      BANK_ACCT             ,
      ON_LINE_AMOUNT        ,
      INSTANT_AMOUNT        ,
      TOTAL_AMOUNT          ,
      SOURCE                ,
      INSERTED_DATE         ,
      CDC                   from weekly_eft_temp union all
    select 
      BILL_TO_RETAILER  ,
      RETAILER_NAME     ,
      STATUS            ,
      ON_LINE_AMOUNT    ,
      INSTANT_AMOUNT    ,
      NON_SWEPT_AMT     ,
      TTYPE             ,
      EXCEPTION_REASON   from weekly_bill_expt_temp;
    I used the union of all, but it doesn't seem to work. I don't know where it's track. I searched on the net but his send me examples for 2 tables tat are similar.

    Any suggestions please

    You must replicate the columns that do not exist fill them with NULL values.

    Perhaps;

    create view eft_view as
      select bill_to_retailer,
             retailer_name,
             name_on_bank_account,
             bank_aba,
             bank_acct,
             null status,
             on_line_amount,
             instant_amount,
             total_amount,
             source,
             inserted_date,
             cdc,
             cast (null as number) non_swept_amt,
             null ttype,
             null exception_reason
        from weekly_eft_temp
      union all
      select bill_to_retailer,
             retailer_name,
             null name_on_bank_account,
             null bank_aba,
             null bank_acct,
             status,
             on_line_amount,
             instant_amount,
             null total_amount,
             null source,
             null inserted_date,
             nul cdc,
             non_swept_amt,
             ttype,
             exception_reason
        from weekly_bill_expt_temp;
    
  • Select different columns using union all

    I'm trying to select all the records of two table

    Select A, B, C from table1
    Union of all the
    Select A, B, D, E, F from table2

    I get results A, B, C columns but not D, E, F.

    What should I do to get all the columns in the result. as A, B, C, D, E, F

    Thank you
    SK

    Hello

    That's what you asked for:

    select         Total_Customer_Qty,  NULL AS Total_Supplier_Qty,  Item_number,  Org,item_id  from table1;
    union all
    select NULL AS Total_Customer_Qty,          Total_Supplier_Qty,  Item_number,  Org,item_id  from table2;
    

    I hope that's what you want, too.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • Documentation about adding column with the DEFAULT value.

    Hello

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_3001.htm#i2198241

    < quote >
    If you add a column, then the initial value of each row in the new column is NULL unless you specify the DEFAULT clause. In this case, Oracle database updates each row in the new column with the value specified for the DEFAULT value. This update operation, in turn, triggers AFTER UPDATE triggers defined on the table.
    < quote >

    I am not able to understand the emphasis on the part AFTER UPDATE while the column with DEFAULT values addition triggers both BEFORE and AFTER triggers defined on UPDATE.

    According to the documents of 11 g

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/statements_3001.htm#i2133105

    n.m. (u) r only changes with the NON NULL columns, but focus on AFTER UPDATE is still there. No trigger defined on the fire of the update in this case.

    This insistence is intended? If not, IMO, it should be changed.

    Kind regards

    Hi Sissi. After further discussion, we have added some information about a change in behavior. Here is what says the next version of the doc:

    When you add a column, the initial value of each row in the new column is null.

    * If you specify the DEFAULT clause for a column NOT NULL, then the default value is stored as metadata, but the column itself is not populated with data. However, the following queries that specify the new column are rewritten so that the default value is returned in the result set.

    This optimized behavior differs from earlier versions, when as part of operation ALTER TABLE Oracle database updated every line in the newly created with the default column and then fired defined update triggers on the table. In this release, no trigger is triggered because the default value is stored only in the form of metadata.

    * If you specify the DEFAULT for a nullable column clause, then the default value is added to existing lines under this ALTER TABLE statement, and any update triggers defined on the table are activated. This behavior also means if you change a NOT NULL column with a default value to be nullable.

    Hope that helps to clarify the matter further.

    Kind regards
    Diana

  • added column WITH byte and char

    What is the difference between adding a column in the table with the DATA type of char(10) AND char (10 bytes)


    Difference between these two

    ALTER TABLE IND
    Char to add a KEY (12 bytes);

    and

    ALTER TABLE IND
    Add a KEY tank (12);


    Pls years

    S

    Check this box:

    SQL> create table test_1 (col1 varchar2(1 byte));
    
    Table created.
    
    SQL> create table test_2 (col1 varchar2(1 char));
    
    Table created.
    
    SQL> insert into test_1 values('Ä');
    insert into test_1 values('Ä')
                              *
    ERROR at line 1:
    ORA-01401: inserted value too large for column
    
    SQL> ed
    Wrote file afiedt.buf
    
      1* insert into test_2 values('Ä')
    SQL> /
    
    1 row created.
    
    SQL> 
    
  • added column with the range?

    Hello

    Is it possible to add a column that can have only a range of values?, ex: Descr_tbl, I need to add the code and descr with id and columns as a composite key identification code and also I need to have the values of code between only 0-63.

    Like this:

    SQL> create table t (n number);
    
    Table created.
    
    SQL> alter table t add constraint t_chk check (n >= 0 and n <= 63);
    
    Table altered.
    
    SQL> insert into t values (0);
    
    1 row created.
    
    SQL> insert into t values (42);
    
    1 row created.
    
    SQL> insert into t values (63);
    
    1 row created.
    
    SQL> insert into t values (66);
    insert into t values (66)
    *
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.T_CHK) violated
    
    SQL> insert into t values (-5);
    insert into t values (-5)
    *
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.T_CHK) violated
    
  • Poblem with union/union all giving ORA-22950

    I use a select statement with the xmlelement to create an xml file.

    There the various unions end in 5, but I always bring a line through.

    I do like that as then I can use this as a cursor in my plsql without having to create lots of cursors when I only need to use a.
    That is to say.
    SELECT  xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                          xmlelement(CUSTOMERNAME, customername),
                          xmlelement(QUOTE,quoteid )))xmlfile
    From cust, quote
    where custid=quotecustid
    and ptype = 'Q'
    UNION
    SELECT  xmlelement("SALES",xmlagg(xmlelement(SALES,
                          xmlelement(CUSTOMERNAME, customername),
                          xmlelement(QUOTE,salesid )))xmlfile
    From cust, sales
    where custid=salescustid
    and ptype = 'S'
    Then, I use a cursor to execute it in a ftp file folder I selected passing ptype as a parameter.

    If I use the union I get ORA-22950 - I have seen other people use UNION all around it.
    If I use union all I'll get a value for the SALE of any line that is

    Any ideas how I can get around this as do not want to continue to create cursors

    The use of different sliders is always the best approach IMO.
    All things considered, it should be more effective than that appearing more "smart" one.

    And there is no need to be explicit cursors, it could just be SELECT INTOs wrapped in a PL/SQL CASE statement, with the appropriate exception handler (if necessary).

    Anyway, if you want to stick with the single-cursor method, there are different ways to do this:

    (1) adding a column selector:

    SELECT xmlfile
    FROM (
      SELECT 'Q' as selector
           , xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                      xmlelement(CUSTOMERNAME, customername),
                      xmlelement(QUOTE,quoteid )))xmlfile
      From cust, quote
      where custid=quotecustid
      and ptype = :1
      UNION ALL
      SELECT 'S'
           , xmlelement("SALES",xmlagg(xmlelement(SALES,
                      xmlelement(CUSTOMERNAME, customername),
                      xmlelement(QUOTE,salesid )))xmlfile
      From cust, sales
      where custid=salescustid
      and ptype = :1
    )
    WHERE selector = :1
    ;
    

    (2) adding a GROUP BY clause, so that XMLAgg returns nothing if no row is selected:

    SELECT xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                    xmlelement(CUSTOMERNAME, customername),
                    xmlelement(QUOTE,quoteid )))xmlfile
    From cust, quote
    where custid=quotecustid
    and ptype = :1
    GROUP BY null
    UNION ALL
    SELECT xmlelement("SALES",xmlagg(xmlelement(SALES,
                    xmlelement(CUSTOMERNAME, customername),
                    xmlelement(QUOTE,salesid )))xmlfile
    From cust, sales
    where custid=salescustid
    and ptype = :1
    GROUP BY null
    ;
    

    (3) subqueries:

    SELECT case :1
            when 'Q' then ( SELECT ... )
            when 'S' then ( SELECT ... )
          end as xmlfile
    FROM dual
    ;
    
  • [8i] need help on query with a subquery/inline using UNION ALL view

    OK, first of all let's start with some background info:
    (1) I work in 8i
    (2) some samples for my problem (please excuse the additional columns of data not used to this problem; I already had the sample laying around tables):
    CREATE TABLE     vbom
    (
         part_nbr     char(25)     
    ,     bom_doc_nbr     char(25)     
    ,     bill_level     number          
    ,     comp_part_nbr     char(25)     
    ,     qty_per          number
    );
    --technically has primary and foreign keys, but whatever...
    --part_nbr is your top level (0) parent
    --comp_part_nbr is the specific child
    --bom_doc_nbr is the parent of the child (comp_part_nbr) and may be either part_nbr or a child of part_nbr that is also a parent
    
    INSERT INTO vbom
    VALUES ('SAMPLE-1','SAMPLE-1', 1,'SAMPLE-2',1);
    
    CREATE TABLE     rqmt
    (
         comp_part_nbr     char(25)     
    ,     prnt_part_nbr     char(25)
    ,     ord_nbr          char(10)     
    ,     sub_ord_nbr     char(3)
    ,     qty_reqd     number
    ,     qty_issued     number
    ,     date_reqd     date
    ,     rqmt_stat     char(2)
    ,     rqmt_type     char(2)
    );
    
    INSERT INTO rqmt
    VALUES ('SAMPLE-1','','S0000TEST1',001,30,0,TO_DATE('06/01/2010','mm/dd/yyyy'),'AL','ID');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000054963',001,15,10,TO_DATE('04/01/2010','mm/dd/yyyy'),'CL','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000032562',001,5,5,TO_DATE('04/15/2010','mm/dd/yyyy'),'IS','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000022341',001,5,4,TO_DATE('04/20/2010','mm/dd/yyyy'),'SH','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000043469',001,10,0,TO_DATE('04/30/2010','mm/dd/yyyy'),'AL','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000071235',001,10,0,TO_DATE('05/01/2010','mm/dd/yyyy'),'OP','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000061224',001,5,0,TO_DATE('05/15/2010','mm/dd/yyyy'),'FP','DD');
    INSERT INTO rqmt
    VALUES ('SAMPLE-2','SAMPLE-1','0000033294',001,5,0,TO_DATE('05/25/2010','mm/dd/yyyy'),'PL','DD');
    So, my first question was that I needed to find in the table RQMT who corresponded with everything on my VBOM have vbom.part_nbr table ' SAMPLE-1'. '. (Please note, in reality the VBOM table has thousands of rows of data, rather than just the 1 I have planned, some of them sharing the same vbom.part_nbr, others not). In addition to finding all RQMT data corresponding to the vbom.comp_part_nbr to vbom.part_nbr (where vbom.comp_part_nbr = rqmt.comp_part_nbr), I also need to find RQMT data for vbom.part_nbr itself (then, records where vbom.part_nbr = rqmt.comp_part_nbr).

    To resolve this problem, I started with the following query:
    SELECT     v.bill_level          AS bill_lvl
    ,     v.comp_part_nbr          AS component
    ,     v.bom_doc_nbr          AS parent
    FROM     VBOM v
    WHERE     v.part_nbr     ='SAMPLE-1'
    UNION ALL
    SELECT     0               AS bill_lvl
    ,     'SAMPLE-1'          AS component
    ,     NULL               AS parent
    FROM DUAL
    It allows me to add a line to the top of the page parent (vbom.part_nbr), which does not exist in vbom.
    My first question is, is UNION ALL of the best way to do it, or could I do a kind of instruction based on the line number box (or something) that would be better? (in this application, or in the final query)

    Then, I used the above query as a point of view online:
    SELECT     a.bill_lvl
    ,     a.component
    ,     a.parent
    ,     r.ord_nbr
    ,     r.sub_ord_nbr
    ,     r.qty_reqd
    FROM     (
         SELECT     v.bill_level          AS bill_lvl
         ,     v.comp_part_nbr          AS component
         ,     v.bom_doc_nbr          AS parent
         FROM     VBOM v
         WHERE     v.part_nbr     ='SAMPLE-1'
         UNION ALL
         SELECT     0               AS bill_lvl
         ,     'SAMPLE-1'          AS component
         ,     NULL               AS parent
         FROM DUAL
         ) a
    ,     RQMT r
    WHERE     a.component     = r.comp_part_nbr
    The problem here is that I have the same results (7 files) with the above query as I do with:
    SELECT     v.bill_level
    ,     v.comp_part_nbr
    ,     v.bom_doc_nbr
    ,     r.ord_nbr
    ,     r.sub_ord_nbr
    ,     r.qty_reqd
    FROM     VBOM v
    ,     RQMT r
    WHERE     v.comp_part_nbr     = r.comp_part_nbr
    AND     v.part_nbr     = 'SAMPLE-1'
    .. .it does not include RQMT recording for rqmt.comp_part_nbr = "SAMPLE-1'.

    To understand what was going on, I ran:
    SELECT     a.bill_lvl
    ,     a.component
    ,     a.parent
    FROM     (
         SELECT     v.bill_level          AS bill_lvl
         ,     v.comp_part_nbr          AS component
         ,     v.bom_doc_nbr          AS parent
         FROM     VBOM v
         WHERE     v.part_nbr     ='SAMPLE-1'
         UNION ALL
         SELECT     0               AS bill_lvl
         ,     'SAMPLE-1'          AS component
         ,     NULL               AS parent
         FROM DUAL
         ) a
    .. .and I get exactly this that I wait, 1 card for the SAMPLE-2 component and 1 plug for SAMPLE-1 (i.e. the recording I generated with the UNION ALL).

    Then I ran:
    SELECT     r.comp_part_nbr
    ,     r.ord_nbr
    ,     r.sub_ord_nbr
    ,     r.qty_reqd
    FROM     RQMT r
    WHERE     r.comp_part_nbr like 'SAMPLE-%'
    .. .and I get all 8 records, whose SAMPLE-1.

    So, it seems that the problem occurred when I join my opinion RQMT one online, although both separately seem to work very well.

    A point to note: all parts of parent and child may not be appointed in the same way as in my example. SAMPLE-1 could have children of the SAMPLE-2, abc123, 20735, for example.

    Any help on this would be appreciated, thanks!

    Hello

    Concerns of problem by comparing 8 literal characters ' SAMPLE-1' for the 25-character CHAR column that contains "SAMPLE 1".»
    17 spaces including the literal or use LPAD or CAST to 25 characters.
    For example:

    SELECT     a.bill_lvl
    ,     a.component
    ,     a.parent
    ,     r.ord_nbr
    ,     r.sub_ord_nbr
    ,     r.qty_reqd
    FROM     (
         SELECT     v.bill_level          AS bill_lvl
         ,     v.comp_part_nbr          AS component
         ,     v.bom_doc_nbr          AS parent
         FROM     VBOM v
         WHERE     v.part_nbr     ='SAMPLE-1'
         UNION ALL
         SELECT     0               AS bill_lvl
         ,     CAST ('SAMPLE-1' AS CHAR (25))               -- CAST added here
                                      AS component
         ,     NULL               AS parent
         FROM DUAL
         ) a
    ,     RQMT r
    WHERE     a.component     = r.comp_part_nbr
    ;
    

    Is there a reason why you use CHAR instead of VARCHAR2? (One reason other than "I can't change it now.", otherwise said.)

  • Union all with addistional field

    Hello

    Maybe this is a stupid question.

    I have two tables with 22 columns.

    Another table with 23 columns

    I want to combine these two tables using union all.

    In the first picture, I want back "NA" as the last field.

    In the second table, last column is varchar2.

    Instead of every column one by one and if I use select * in two queries and add "NA" to one?

    I want the union two queries can order and use it with the clause to retrieve values based on conditions somany.

    So I have to specify the names of column three times.

    I use oracle 10g

    Hello Krishna,

    Try

    select t1.*, 'NA' as  from table1 t1
    union
    select t2.* from table2 t2;
    

    concerning

    Kay

  • How to fill a column with numbers and maintain when adding or deleting lines?

    So far, I've discovered two ways to fill a column with the number:

    1. Enter '1' in a single cell, '2' in the one below, select both, and then use the yellow dot to drag down - it will do the rest.

    2 create a formula such as 'A2 + 1' and drag also.

    However, in both cases it will work if I manually this continues to do for each newly added line at the bottom. Now, that alone would not be that big of a problem if it wasn't for the fact that I'm working with a table where the lines can be added among other rows in the future.

    Having said that, could someone please tell me how to create a column with a number that will increase automatically? I mean - if I add a new line between line 56 and 57, I want the new line to have a '57"in it, and the" old 57 "would now be"58"and so on." " I don't want to drag the whole column, which can be hundreds if not more than a thousand lines.

    Try to put this in the cells in the column:

    = ROW()

    In the formula, you can add or subtract a number if necessary to get the starting number that you need.

    SG

  • Why UNION ALL allows no column names only when a literal is used and there is at least 3 parts of the query?

    An artificial union all:

    SQL> SELECT Dummy FROM Dual ORDER BY Dummy;
    
    D
    -
    X
    
    SQL> SELECT Dummy FROM Dual UNION ALL SELECT Dummy FROM Dual ORDER BY Dummy;
    
    D
    -
    X
    X
    
    SQL> SELECT Dummy FROM Dual UNION ALL SELECT Dummy FROM Dual UNION ALL SELECT Dummy FROM Dual ORDER BY Dummy;
    
    D
    -
    X
    X
    X
    
    
    

    It literally changes it:

    SQL> SELECT NULL A FROM Dual ORDER BY A;
    
    A
    -
    
    
    SQL> SELECT NULL A FROM Dual UNION ALL SELECT NULL FROM Dual ORDER BY A;
    
    A
    -
    
    
    
    SQL> SELECT NULL A FROM Dual UNION ALL SELECT NULL FROM Dual UNION ALL SELECT NULL FROM Dual ORDER BY A;
    SELECT NULL A FROM Dual UNION ALL SELECT NULL FROM Dual UNION ALL SELECT NULL FROM Dual ORDER BY A
                                                                                                     *
    ERROR at line 1:
    ORA-00904: "A": invalid identifier
    
    
    SQL> SELECT NULL A FROM Dual UNION ALL SELECT NULL FROM Dual UNION ALL SELECT NULL FROM Dual ORDER BY 1;
    
    A
    -
    
    
    
    
    

    Why 3 is the magic number?

    My friend, this is what I would call a "bug".

    However, my opinion doesn't matter, because I do not work for Oracle

    You opened a SR with Oracle?

  • Please help me with the Alternative of queries to replace the UNION ALL for two queries

    Hi all

    I have the query to retrieve assets employees salary count and in so far as below:

    Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of

    (select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1

    where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")

    UNION ALL

    Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the

    where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "

    Group of emp_no, ename;

    In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.

    But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.

    Advice me with request to read the table once to fetch the same data as the above query.

    Thanks in advance.


    Hello

    Thanks for the display of the data of the sample; It's very useful!

    I think OP wants something like this:

    WITH cutoff_dates AS

    (

    SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL

    SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014

    )

    SELECT e.emp_no, e.ename

    , NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010

    , NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014

    E employee

    JOIN cutoff_dates c ON e.effective_date<=>

    WHERE DOES NOT EXIST)

    SELECT 1

    Of employee_deletion ed

    WHERE ed.emp_no = e.emp_no

    AND ed.deletion_date<=>

    )

    E.emp_no GROUP, e.ename

    ORDER BY e.emp_no

    ;

    Output of your sample data:

    EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014

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

    1 Mickey 450 0

    2 Donald 750 0

  • For all the records for each record double, I need to get a single column with null or 0.

    Hi all

    I have a requirement where I need to get all the records, for each record in double, I need to get a single column with null or 0.

    create table a1

    (

    Identification number,

    VARCHAR2 (100), the point

    part varchar2 (100));

    Insert into a1

    values (1, 'ABC', 'A1');

    Insert into a1

    values (2, 'DEF', 'A2');

    TABLE A

    PART ITEM ID

    1 ABC A1

    1 ABC A1

    1 ABC A1

    DEF 2 A2

    DEF 2 A2

    3 DEF A2

    O/P

    PART ITEM ID

    1 ABC A1

    1        ABC             0

    1        ABC             0

    DEF 2 A2

    2       DEF              0

    3       DEF              0

    Thanks in advance.

    Thanks for your help FrankKalush...

    This one will work.

    WITH got_r_num AS

    (

    SELECT NVL (a1.id, a1.id) as id

    NVL (a1.item, a1.item) AS element

    NVL (a1.part, a1.part) IN the framework

    a1.id AS a_id

    ROW_NUMBER () OVER (PARTITION BY a1.id

    ORDER BY NULL

    ) AS r_num

    BY the a1

    )

    SELECT id

    element

    CASE

    WHEN a_id IS NOT NULL

    AND r_num = 1

    THEN part

    ELSE ' 0'

    END in the framework

    OF got_r_num

    ;

Maybe you are looking for

  • How can I contact the creator of a character?

    I just want to communicate with the creator of a character that I love... is there a way to send a message to them that I missed?

  • "Unknown device" USB Barcode scanner, problem with the USB controller driver?

    Hello I need assistance with our Barcode Scanners that doesn't work on our newly purchased computers at HP with Windows7 Pro x 64 operating systems. The brand and model of the bar code scanner is: Datalogic Heron D130 USB. When you connect the scanne

  • Changing the language in the BONE or...

    I bought a laptop in Italy a few days - Satellite Pro M40X 266. Understand that the change in the operating system to the English Version can be download from the Toshiba site. Attached is my 1st question, if I download/change language from Italian t

  • Pockets of poor quality on the rocket.

    Hey,. I just added a few album covers using the drag-and - déposer on the "rocket". And the album art is not very clear compared to the art of the album in the songs accompanying the "rocket". So my question is how to get on the rocket high quality

  • HP Photosmart 5520 411 server connection error

    Hello Does anyone know how to solve Server connection error 411.? I have a Mac, and until recently still for more Mac Wireless scan was fine. Without wire is connected and the computer scan is enabled. The e-mail address and the PIN is correct. Thank