Union Sql

Hi All,
How do i merge or use union on two different table with 2 columns less in the 2nd table like
select col1, col2, col3, col4 from table a
union
select col1, col2 from table b
thanks n regards

Hi Jens,
im getting the same output with two null columns. it
is not making union.
any other alternate. im using oracle 9i.
thanks n regardsWhat exactly do you mean by this? Are you not seeing any rows from the second table? Are you getting an error? Tell us exactly the query you are doing and exactly the problem you are encountering. Saying you get the same output is useless when you didn't tell us what the original output was.
You may need to use TO_DATE(null) or TO_NUMBER(null) rather than plain null to ensure the extra fields have the same datatype as your actual fields.
But as you describe your original problem, this is the solution.

Similar Messages

  • UNION  SQL QUERY

    Hello
    i have problem in sql query
    there two queries
    the first
    SELECT m.segment1
    || '.'
    || m.segment2
    || '.'
    || m.segment3
    || '.'
    || m.segment4
    || '.'
    || m.segment5
    || '.'
    || m.segment6 ACCOUNT,q.description,
    NVL ((SUM (l.entered_dr) - SUM (l.entered_cr)),
    SUM (l.entered_dr)
    ) debt,
    NVL (NULL, 0) credit
    FROM gl_code_combinations m,
    gl_je_batches c,
    gl_je_categories n,
    gl_je_headers h,
    gl_je_lines l,
    gl_sets_of_books t,
    fnd_flex_values_vl q
    WHERE m.segment1 || '.' || m.segment2 || '.' || m.segment3
    BETWEEN NVL (SUBSTR (:account_from, 1, 9),
    m.segment1 || '.' || m.segment2 || '.' || m.segment3
    AND NVL (SUBSTR (:account_to, 1, 9),
    m.segment1 || '.' || m.segment2 || '.' || m.segment3
    AND m.segment4 || '.' || m.segment5 || '.' || m.segment6
    BETWEEN NVL (SUBSTR (:account_from, 11, 23),
    m.segment4 || '.' || m.segment5 || '.' || m.segment6
    AND NVL (SUBSTR (:account_to, 11, 23),
    segment4 || '.' || segment5 || '.' || segment6
    AND h.default_effective_date BETWEEN :from_date AND :TO_DATE
    AND n.user_je_category_name = NVL (:cate, n.user_je_category_name)
    AND m.chart_of_accounts_id = :chartid
    AND q.flex_value = m.segment5
    AND q.parent_flex_value_low = m.segment4
    AND q.flex_value_set_id = 1009648
    AND h.je_header_id = l.je_header_id
    AND h.je_batch_id = c.je_batch_id
    AND l.code_combination_id = m.code_combination_id
    AND m.chart_of_accounts_id = t.chart_of_accounts_id
    AND l.set_of_books_id = t.set_of_books_id
    AND h.je_category = n.je_category_name
    AND ( n.user_je_category_name LIKE 'PAS_%'
    OR n.user_je_category_name LIKE 'BS_%'
    OR n.user_je_category_name LIKE 'MS_%'
    OR n.user_je_category_name LIKE 'PS_%'
    OR n.user_je_category_name LIKE 'TY_%'
    OR n.user_je_category_name LIKE 'VEH_%'
    OR n.user_je_category_name LIKE 'WS_%'
    GROUP BY m.segment1
    || '.'
    || m.segment2
    || '.'
    || m.segment3
    || '.'
    || m.segment4
    || '.'
    || m.segment5
    || '.'
    || m.segment6,
    q.description,
    M.CODE_COMBINATION_ID
    and this query return 13 rows
    the second query is
    select
    m.segment1
    || '.'
    || m.segment2
    || '.'
    || m.segment3
    || '.'
    || m.segment4
    || '.'
    || m.segment5
    || '.'
    || m.segment6 ACCOUNT,q.description,NVL (null,0) Debit,NVL(SUM(l.ENTERED_CR ),0)Credit
    from gl_code_combinations M,
    gl_je_batches c,
    gl_je_categories N,
    GL_JE_HEADERS H,
    GL_JE_LINES L,
    GL_SETS_OF_BOOKS T,
    fnd_flex_values_vl q
    where M.segment1 || '.' || M.segment2 || '.' ||M.segment3
    BETWEEN NVL (SUBSTR (:ACCOUNT_FROM, 1, 9),
    M.segment1 || '.' ||M.segment2 || '.' || M.segment3
    AND NVL (SUBSTR (:ACCOUNT_TO, 1, 9),
    M.segment1 || '.' || M.segment2 || '.' ||M.segment3
    AND M.segment4 || '.' ||M.segment5 || '.' || M.segment6
    BETWEEN NVL (SUBSTR(:ACCOUNT_FROM, 11, 23),
    M. segment4 || '.' ||M.segment5 || '.' || M.segment6
    AND NVL (SUBSTR (:ACCOUNT_TO, 11, 23),
    segment4 || '.' || segment5 || '.' || segment6
    AND H.DEFAULT_EFFECTIVE_DATE BETWEEN :FROM_DATE AND :TO_DATE
    AND N.user_je_category_name=NVL(:CATE,N.user_je_category_name)
    AND q.flex_value = m.segment5
    AND q.parent_flex_value_low = m.segment4
    AND q.flex_value_set_id = 1009648
    AND M.CHART_OF_ACCOUNTS_ID=:CHARTID
    AND H.JE_HEADER_ID=L.JE_HEADER_ID
    AND H.JE_BATCH_ID=C.JE_BATCH_ID
    AND L.CODE_COMBINATION_ID=M.CODE_COMBINATION_ID
    AND M.CHART_OF_ACCOUNTS_ID=T.CHART_OF_ACCOUNTS_ID
    AND L.SET_OF_BOOKS_ID=T.SET_OF_BOOKS_ID
    AND H.JE_CATEGORY=N.JE_CATEGORY_NAME
    AND (N.user_je_category_name NOT LIKE 'PAS_%'AND N.user_je_category_name NOT LIKE 'BS_%'
    AND N.user_je_category_name NOT LIKE 'MS_%' AND N.user_je_category_name NOT LIKE 'PS_%'
    AND N.user_je_category_name NOT LIKE 'TY_%' AND N.user_je_category_name NOT LIKE 'VEH_%'
    AND N.user_je_category_name NOT LIKE 'WS_%'
    OR N.user_je_category_name LIKE 'RE_%')
    GROUP BY m.segment1
    || '.'
    || m.segment2
    || '.'
    || m.segment3
    || '.'
    || m.segment4
    || '.'
    || m.segment5
    || '.'
    || m.segment6 ,
    q.description
    and return 12 rows
    i want to union this querys
    can any programmer help me
    thank

    What the problem in that? I dont get it. You can just use UNION ALL.
    SELECT      m.segment1
              || '.'
              || m.segment2
              || '.'
              || m.segment3
              || '.'
              || m.segment4
              || '.'
              || m.segment5
              || '.'
              || m.segment6 ACCOUNT,q.description,
              NVL ((SUM (l.entered_dr) - SUM (l.entered_cr)),
                   SUM (l.entered_dr)
                  ) debt,
              NVL (NULL, 0) credit
         FROM gl_code_combinations m,
              gl_je_batches c,
              gl_je_categories n,
              gl_je_headers h,
              gl_je_lines l,
              gl_sets_of_books t,
              fnd_flex_values_vl q
        WHERE m.segment1 || '.' || m.segment2 || '.' || m.segment3
                 BETWEEN NVL (SUBSTR (:account_from, 1, 9),
                              m.segment1 || '.' || m.segment2 || '.' || m.segment3
                     AND NVL (SUBSTR (:account_to, 1, 9),
                              m.segment1 || '.' || m.segment2 || '.' || m.segment3
          AND m.segment4 || '.' || m.segment5 || '.' || m.segment6
                 BETWEEN NVL (SUBSTR (:account_from, 11, 23),
                              m.segment4 || '.' || m.segment5 || '.' || m.segment6
                     AND NVL (SUBSTR (:account_to, 11, 23),
                              segment4 || '.' || segment5 || '.' || segment6
          AND h.default_effective_date BETWEEN :from_date AND :TO_DATE
          AND n.user_je_category_name = NVL (:cate, n.user_je_category_name)
          AND m.chart_of_accounts_id = :chartid
           AND q.flex_value = m.segment5
          AND q.parent_flex_value_low = m.segment4
          AND q.flex_value_set_id = 1009648
          AND h.je_header_id = l.je_header_id
          AND h.je_batch_id = c.je_batch_id
          AND l.code_combination_id = m.code_combination_id
          AND m.chart_of_accounts_id = t.chart_of_accounts_id
          AND l.set_of_books_id = t.set_of_books_id
          AND h.je_category = n.je_category_name
          AND (   n.user_je_category_name LIKE 'PAS_%'
               OR n.user_je_category_name LIKE 'BS_%'
               OR n.user_je_category_name LIKE 'MS_%'
               OR n.user_je_category_name LIKE 'PS_%'
               OR n.user_je_category_name LIKE 'TY_%'
               OR n.user_je_category_name LIKE 'VEH_%'
               OR n.user_je_category_name LIKE 'WS_%'
    GROUP BY    m.segment1
              || '.'
              || m.segment2
              || '.'
              || m.segment3
              || '.'
              || m.segment4
              || '.'
              || m.segment5
              || '.'
              || m.segment6,
              q.description,
              M.CODE_COMBINATION_ID
    union all
    select
       m.segment1
              || '.'
              || m.segment2
              || '.'
              || m.segment3
              || '.'
              || m.segment4
              || '.'
              || m.segment5
              || '.'
              || m.segment6 ACCOUNT,q.description,NVL (null,0) Debit,NVL(SUM(l.ENTERED_CR ),0)Credit
    from gl_code_combinations M,
    gl_je_batches c,
    gl_je_categories N,
    GL_JE_HEADERS H,
    GL_JE_LINES L,
    GL_SETS_OF_BOOKS T,
    fnd_flex_values_vl q
    where M.segment1 || '.' || M.segment2 || '.' ||M.segment3
    BETWEEN NVL (SUBSTR (:ACCOUNT_FROM, 1, 9),
    M.segment1 || '.' ||M.segment2 || '.' || M.segment3
    AND NVL (SUBSTR (:ACCOUNT_TO, 1, 9),
    M.segment1 || '.' || M.segment2 || '.' ||M.segment3
    AND M.segment4 || '.' ||M.segment5 || '.' || M.segment6
    BETWEEN NVL (SUBSTR(:ACCOUNT_FROM, 11, 23),
    M. segment4 || '.' ||M.segment5 || '.' || M.segment6
    AND NVL (SUBSTR (:ACCOUNT_TO, 11, 23),
    segment4 || '.' || segment5 || '.' || segment6
    AND H.DEFAULT_EFFECTIVE_DATE BETWEEN :FROM_DATE AND :TO_DATE
    AND N.user_je_category_name=NVL(:CATE,N.user_je_category_name)
      AND q.flex_value = m.segment5
          AND q.parent_flex_value_low = m.segment4
          AND q.flex_value_set_id = 1009648
    AND M.CHART_OF_ACCOUNTS_ID=:CHARTID
    AND H.JE_HEADER_ID=L.JE_HEADER_ID
    AND H.JE_BATCH_ID=C.JE_BATCH_ID
    AND L.CODE_COMBINATION_ID=M.CODE_COMBINATION_ID
    AND M.CHART_OF_ACCOUNTS_ID=T.CHART_OF_ACCOUNTS_ID
    AND L.SET_OF_BOOKS_ID=T.SET_OF_BOOKS_ID
    AND H.JE_CATEGORY=N.JE_CATEGORY_NAME
    AND (N.user_je_category_name NOT LIKE 'PAS_%'AND N.user_je_category_name NOT LIKE 'BS_%'
    AND N.user_je_category_name NOT LIKE 'MS_%' AND N.user_je_category_name NOT LIKE 'PS_%'
    AND N.user_je_category_name NOT LIKE 'TY_%' AND N.user_je_category_name NOT LIKE 'VEH_%'
    AND N.user_je_category_name NOT LIKE 'WS_%'
    OR N.user_je_category_name LIKE 'RE_%')
      GROUP BY  m.segment1
              || '.'
              || m.segment2
              || '.'
              || m.segment3
              || '.'
              || m.segment4
              || '.'
              || m.segment5
              || '.'
              || m.segment6 ,
              q.description

  • Union SQL Statements in a DataTemplate

    I am in the process of converting a bunch (150+) BI Answers reports into about 9 Publisher reports(we have 9 dashboards now).
    Due to business logic and other considerations I have a large amount of reports that leverage unions.
    How do I have to handle SQL Unions statements in a Data Template?
    Do I have to break them up?
    How do I map multiple data sources to one data element name. I have some instances where four or five different SQL statements make one BI Report
    ie
    <element name="PublisherName" value="BIAnswers1"/>
    <element name="PublisherName" value="BIAnswer2"/>
    <element name="PublisherName" value="BIAnswers3"/>

    I had to go back to the orginal SQL with the union. Wha tI don't understand is that I get the correct amount of rows but the fields do not seem to be mapped correctly. They are all blank. I get the 20 rows I need to get but no data is in any of the elements.
    I can check the SQL in the BI answers direct sql function and it functions as desired.
    XML:
    <dataQuery>
              <sqlStatement name="CallData">
              <![CDATA[SELECT saw_0, saw_1 FROM ((SELECT "- Reporting Date"."Reporting Month" saw_0, FILTER(FILTER("- CMS Call Metrics"."# CMS Calls Answered" USING (("- CMS Details"."CMS Interval" = 0.00) AND ("- VDN Details"."VDN Area" = 'SVC') AND ("- VDN Details"."VDN Business Unit" = 'HLT') AND ("- Reporting Date"."Reporting Date" Between "- VDN Details"."VDN Start Date" and "- VDN Details"."VDN End Date"))) USING ("- VDN Details"."VDN Partner" = 'UHG')) saw_1 FROM Finance WHERE ("- Reporting Date"."Reporting Year" =  VALUEOF("CURRENT_YEAR")) AND ("- Reporting Date"."Reporting Month" <>  VALUEOF("CURRENT_MONTH"))) UNION (SELECT "- Reporting Date"."Reporting Month" saw_0, 0 saw_1 FROM Finance WHERE "- Reporting Date"."Reporting Year" =  VALUEOF("CURRENT_YEAR"))) t1 ORDER BY saw_0
    ]]></sqlStatement>
         </dataQuery>
         <dataStructure>
              <group name="CallData" source="CallData">
                        <element name="REPORTINGMONTH" value="saw_0"/>
                        <element name="CALLSANSWERED" value="saw_1"/>
              </group>

  • Pb of union sql request

    hi,
    I have to execute this sql equest
    Code:
    SELECT ID, NOM, DEFINITION FROM MOT WHERE NOM like 'crédit %'
    UNION SELECT ID, NOM, DEFINITION FROM MOT WHERE NOM LIKE ' crédit' + '%'
    UNION SELECT ID, NOM, DEFINITION FROM MOT WHERE NOM LIKE '%' +" "+ 'crédit' +" "+ '%';
    but it is not possible because the fields NOM, DEFINITION are text fields and not varchar fields and it is not possible to executethis union clause .
    Could you help me to transform this request to another to execute it?
    It is very urgent, if you could help me it would be very kind from you!
    Best regards.
    Nathalie

    Hello,
    Sorry, I just re-read your post and to do the ordering there's a couple of ways I can think of to do it. I'm sure others can come up with something a little bit neater but this should help along the way:
    create table dt_test_order (col1 varchar2(100));
    insert into dt_test_order values('credit');
    insert into dt_test_order values('credit+something');
    insert into dt_test_order values('credit+something else');
    insert into dt_test_order values('something credit+something');
    insert into dt_test_order values('something credit+something else');
    insert into dt_test_order values('something else credit+something else');
    SELECT
         CASE
              WHEN col1 = 'credit' THEN
                   1
              WHEN col1 LIKE 'credit+%' THEN
                   2
              WHEN col1 LIKE '%credit+%' THEN
                   3          
         END col1_order,
         col1
    FROM
         dt_test_order;
    SELECT
         col1
    FROM
         dt_test_order
    ORDER BY
         CASE
              WHEN col1 = 'credit' THEN
                   1
              WHEN col1 LIKE 'credit+%' THEN
                   2
              WHEN col1 LIKE '%credit+%' THEN
                   3          
         END,
         LENGTH(col1);
    SELECT
         col1
    FROM
         dt_test_order
    ORDER BY
         CASE
              WHEN col1 = 'credit' THEN
                   1
              WHEN col1 LIKE 'credit+%' THEN
                   2
              WHEN col1 LIKE '%credit+%' THEN
                   3          
         END,
         col1;
    SELECT
         col1
    FROM
         dt_test_order
    ORDER BY
         CASE
              WHEN col1 = 'credit' THEN
                   1 + LENGTH(col1)
              WHEN col1 LIKE 'credit+%' THEN
                   2 + LENGTH(col1)
              WHEN col1 LIKE '%credit+%' THEN
                   3 + LENGTH(col1)          
         END;There's a few variations on the same theme.
    HTH
    David

  • Alternative to UNION SQL Oracle 11g

    Hi,
    is any possibility to replace this SQL statement with another one?
    Be aware that this one works and the tables are not identical.
    String statement =" SELECT id, "+
         " sender_id, "+
         " date_created "+
         " FROM DOCUMENT_ARCHIVE da "+
         " where da.SOURCE_FILE_NAME = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' "+
         " union all "+
         " select file_id,"+
         " sender_id,"+
         " date_created "+
         " from DOCUMENT_FILE df "+
         " WHERE df.SOURCE_FILE_NAME = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' ";

    Why do you feel the need to replace it if it gives correct results? If you need to union, then you need to union. Most other structures would not give identical results, that is, one row for each occurrence in each table.
    About the only change that you could make would be to create a view along the lines of:
    CREATE VIEW combined AS
    SELECT id, sender_id, date_created, source_file_name
    FROM document_archive
    UNION ALL
    SELECT id, sender_id, date_created, source_file_name
    FROM document_fileThen query the view like:
    SELECT id, sender_id, date_created
    FROM combined
    WHERE source_file_name = 'shpaig0140_shpsts_shpaig_C2KRMP1.txt' As a side note, I hope that your real code uses bind variables instead of string literals.
    John

  • Help with UNION sql statement......

    Hi guys,
    So I've got 3 tables (CHILD, TEENANGER and ADULT) and each have a column called 'Planned_Dosage_Date' and 'Actual_Dosage_Date'.
    I have put together a SELECT statement like this:
    SELECT     
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITR.PLANNED_DOSAGE_DATE || '/' || ITR.ACTUAL_DOSAGE_DATE
    FROM
        PAT_TR_EVENT ITEV,
        PAT_MEDICAL_PLANICPL,
        PAT_EXAMINATION ITR
    WHERE
        ITEV.AGE_SECTOR = ICPL.AGE_SECTOR
    AND ITEV.ID_NO = ITR.ID_NO
    AND ITEV.ID_NO = 269
    AND ITEV.MED_NO = 3200
    UNION
    SELECT
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE
    FROM
        PAT_TRC_EVENT IYEV,
        PAT_MEDICAL_PLAN ICPL,
        PAT_EXAMINATION ITR,   
        PAT_EXAMINATION_COUNTRY ITRC,
        PAT_TR_EVENT ITEV
    WHERE
        IYEV.AGE_SECTOR = ICPL.AGE_SECTOR
        AND IYEV.MED_NO = ITEV.MED_NO
        AND IYEV.ID_NO = ITR.ID_NO
        AND IYEV.ID_NO = ITRC.ID_NO
        AND IYEV.ID_NO = ITEV.ID_NO
        AND IYEV.COUNTRY_CODE = ITRC.COUNTRY_CODE
        AND IYEV.ID_NO = 269
        AND IYEV.MED_NO = 3200
    UNION
    SELECT
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE
    FROM
         PAT_TR_EVENT ITEV,
         PAT_MEDICAL_PLAN ICPL,
         PAT_EXAMINATION ITR,
         PAT_TU_EVENT IUEV,
         PAT_EXAMINATION_UNIT ITU,
         PAT_EXAMINATION_COUNTRY ITRC,
         PAT_TRC_EVENT IYEV
    WHERE
         IUEV.AGE_SECTOR = ICPL.AGE_SECTOR
         AND IUEV.MED_NO = ITEV.MED_NO
         AND IUEV.MED_NO = IYEV.MED_NO
         AND IUEV.ID_NO=ITR.ID_NO
         AND IUEV.ID_NO=ITRC.ID_NO
         AND IUEV.ID_NO=ITU.ID_NO
         AND IUEV.ID_NO = ITEV.ID_NO
         AND IUEV.ID_NO = IYEV.ID_NO
         AND IUEV.COUNTRY_CODE=ITRC.COUNTRY_CODE 
         AND IUEV.COUNTRY_CODE=ITU.COUNTRY_CODE
         AND IUEV.COUNTRY_CODE = IYEV.COUNTRY_CODE
         AND IUEV.ID_NO= 269
         AND IUEV.MED_NO = 3200
    ORDER BY COUNTRY_DESC ASC, UNIT_NO ASCNow the output from this is:
    AGE_SECTOR                AGE_SECTOR_CODE            ITR. PLANNED_DOSAGE_DATE/ITR.ACTUAL_DOSAGE_DATE
    10-20                               ADU                                                       01-JAN-09/07-FEB-09
    What I want is for the results of:
    ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE
    ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE
    to also be printed so it looks like:
    AGE_SECTOR        AGE_SECTOR_CODE       ITR. PLANNED_DOSAGE_DATE/ITR.ACTUAL_DOSAGE_DATE         ITRC.PLANNED_DOSAGE_DATE/ITRC.ACTUAL_DOSAGE_DATE    ITU.PLANNED_DOSAGE_DATE/ITU.ACTUAL_DOSAGE_DATE
    10-20                    ADU                                   01-JAN-09/07-FEB-09                                    01-MAR-09/07-JUL-09                 01-DEC-08/07-DEC-08How can this be achieved? Am I using the UNION statemen in the incorrect way?
    Thanks!
    Edited by: Sastry on Oct 29, 2009 2:48 AM
    Edited by: Sastry on Oct 29, 2009 2:57 AM
    Edited by: Sastry on Oct 29, 2009 2:58 AM
    Edited by: Sastry on Oct 29, 2009 3:01 AM
    Edited by: Sastry on Oct 29, 2009 3:09 AM
    Edited by: Sastry on Oct 29, 2009 3:10 AM

    I don't think you should be using union here - you will lose the data from soem of the 3 sectors if the dates are the same as UNION does a unique sort. Maybe use UNION ALL, but I think you'd be better off joining.
    Not tested, and you may wish to review whether you need to use outer joins in the last query (What happens if there's no dates for some of the 3 sections?), but something like this:
    WITH itr AS
        SELECT     
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITR.PLANNED_DOSAGE_DATE || '/' || ITR.ACTUAL_DOSAGE_DATE AS dt
        FROM
            PAT_TR_EVENT ITEV,
            PAT_MEDICAL_PLANICPL,
            PAT_EXAMINATION ITR
        WHERE
            ITEV.AGE_SECTOR = ICPL.AGE_SECTOR
        AND ITEV.ID_NO = ITR.ID_NO
        AND ITEV.ID_NO = 269
        AND ITEV.MED_NO = 3200
    itrc AS
        SELECT
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE AS dt
        FROM
            PAT_TRC_EVENT IYEV,
            PAT_MEDICAL_PLAN ICPL,
            PAT_EXAMINATION ITR,   
            PAT_EXAMINATION_COUNTRY ITRC,
            PAT_TR_EVENT ITEV
        WHERE
            IYEV.AGE_SECTOR = ICPL.AGE_SECTOR
            AND IYEV.MED_NO = ITEV.MED_NO
            AND IYEV.ID_NO = ITR.ID_NO
            AND IYEV.ID_NO = ITRC.ID_NO
            AND IYEV.ID_NO = ITEV.ID_NO
            AND IYEV.COUNTRY_CODE = ITRC.COUNTRY_CODE
            AND IYEV.ID_NO = 269
            AND IYEV.MED_NO = 3200
    itu AS
        SELECT
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE AS dt
        FROM
             PAT_TR_EVENT ITEV,
             PAT_MEDICAL_PLAN ICPL,
             PAT_EXAMINATION ITR,
             PAT_TU_EVENT IUEV,
             PAT_EXAMINATION_UNIT ITU,
             PAT_EXAMINATION_COUNTRY ITRC,
             PAT_TRC_EVENT IYEV
        WHERE
             IUEV.AGE_SECTOR = ICPL.AGE_SECTOR
             AND IUEV.MED_NO = ITEV.MED_NO
             AND IUEV.MED_NO = IYEV.MED_NO
             AND IUEV.ID_NO=ITR.ID_NO
             AND IUEV.ID_NO=ITRC.ID_NO
             AND IUEV.ID_NO=ITU.ID_NO
             AND IUEV.ID_NO = ITEV.ID_NO
             AND IUEV.ID_NO = IYEV.ID_NO
             AND IUEV.COUNTRY_CODE=ITRC.COUNTRY_CODE 
             AND IUEV.COUNTRY_CODE=ITU.COUNTRY_CODE
             AND IUEV.COUNTRY_CODE = IYEV.COUNTRY_CODE
             AND IUEV.ID_NO= 269
             AND IUEV.MED_NO = 3200
    SELECT itr.age_sector,
           itr.age_sector_code,
           itr.dt AS itr_dates,
           itrc.dt AS itrc_dates,
           itu.dt AS itu_dates
    FROM itr
    JOIN itrc ON itrc.age_sector = itr.age_sector_code
    JOIN itu ON itu.age_sector_code = itr.age_sector_code

  • WHERE clause to UNION SQL in VOImpl

    Hey gurus,
    I need the ability to add a condition to VOImpl for user_id to both queries in a UNION statement. However, setWhereClause only adds condition to end of the query. Any suggestions? I tried doing an inline select and was unable because of "dual".
    Thanks,
    -Scott
    select 'Sys' x from dual where exists (
    select responsibility_name from fnd_user_responsibility fur,
    fnd_responsibility_tl frt
    where user_id = 16448
    and frt.responsibility_id = fur.responsibility_id
    and frt.responsibility_name = 'System Administrator')
    union
    select 'NoSys' x from dual where not exists (
    select responsibility_name from fnd_user_responsibility fur,
    fnd_responsibility_tl frt
    where user_id = 16448
    and frt.responsibility_id = fur.responsibility_id
    and frt.responsibility_name = 'System Administrator')

    You can have the condition in the original query itself and in the VOImpl, just pass the parameter.
    select 'Sys' x from dual where exists (
    select responsibility_name from fnd_user_responsibility fur,
    fnd_responsibility_tl frt
    where user_id = :1
    and frt.responsibility_id = fur.responsibility_id
    and frt.responsibility_name = 'System Administrator')
    union
    select 'NoSys' x from dual where not exists (
    select responsibility_name from fnd_user_responsibility fur,
    fnd_responsibility_tl frt
    where user_id = :2
    and frt.responsibility_id = fur.responsibility_id
    and frt.responsibility_name = 'System Administrator')Cheers
    Ganesh

  • UNION statement in ABAP SQL

    Hi,
    How to achieve the UNION SQL operation results in ABAP? To be specific, I want to retrieve STCD1 field value from vendor master table (LFA1) for all vendors (LIFNR) that exist in table BSIK or BSAK.
    And I want to achieve the results in single SQL statement. So in essence, the resultant SQL would be something like:
    SELECT STCD1
    INTO TABLE my_internal_table
    FROM LFA1
    WHERE LIFNR IN (SELECT DISTINCT LIFNR
                                                FROM BSIK
                                UNION
                                SELECT DISTINCT LIFNR
                                               FROM BSAK)
    But the UNION is not a valid keyword in ABAP. Any idea how to achieve this?
    Regards,
    Chetan

    hi chetan,
    do you have any where condition to filter the records from bsak and bsik?
    your requirement cannot be realized in a single statement.
    you have to use two separate selects from bsak and bsik, then, collect all the vendors in one internal table and at last you have to use this table to get the vendor info from lfa1.
    regards,
    ravi

  • Can I create a worksheet with "union" or subquery in my SQL?

    I tried to create a worksheet with a SQL contains "union" and sub-query, but the Discoverer doesn't seem to support that.
    Can anyone help?
    Fiona

    Hi,
    You cannot union folders together in a workbook. If you really need to use UNIONs (and often there are alternatives) then you can put your UNION SQL in a custom folder using Discoverer Administrator or create a view at the database level.
    Rod West

  • Query in Order By clause used with UNION

    When tryna execute the below qurey I get
    ORA-01784 - ORDER BY item must be the number of a SELECT-list expression
    Please help me resolve this asap.
    SELECT cm_workqueue.WQUEUEID_REF,cm_workqueue.WQUEUEID_CODE,cm_workqueue.mstr_queue_encode,cm_workqueue.desc_text
    FROM cm_workqueue,
    cm_wkqueue_role,
    atrt_role
    WHERE cm_workqueue.MSTR_QUEUE_ENCODE = 10000000
    AND cm_workqueue.WQUEUEID_REF = cm_wkqueue_role.WQUEUEID_REF
    AND atrt_role.ROLEID_REF = cm_wkqueue_role.roleid_ref
    AND cm_wkqueue_role.REFERRAL_YORN_ENCODE = 10000000
    AND cm_workqueue.STATUS_REF = 10000000
    AND cm_wkqueue_role.STATUS_REF = 10000000
    UNION
    SELECT cm_workqueue.WQUEUEID_REF,cm_workqueue.WQUEUEID_CODE,cm_workqueue.mstr_queue_encode,cm_workqueue.desc_text
    FROM cm_workqueue,
    cm_wkqueue_role,
    atrt_role
    WHERE cm_workqueue.mstr_queue_encode = 10000001
    AND cm_workqueue.status_ref = 10000000
    AND cm_wkqueue_role.wqurolid_ref = 1
    AND EXISTS (
    SELECT 1
    FROM cm_filterset f,
    cm_wkqueue_role cmr
    WHERE f.wqueueid_ref = cm_workqueue.wqueueid_ref
    AND f.status_ref = 10000000
    AND cmr.roleid_ref = atrt_role.roleid_ref
    AND cmr.wqueueid_ref = f.mstrquid_ref
    AND cmr.referral_yorn_encode = 10000000
    AND cmr.status_ref = 10000000)
    ORDER BY CASE
    WHEN cm_workqueue.wqueueid_ref < 999 THEN 1
    ELSE cm_workqueue.mstr_queue_encode
    END,
    LOWER (cm_workqueue.desc_text)

    To be correct, the column names in the order by must be the name of the column alias or the number of the selected column. If you don't give a column alias, the column name of the first select is taken.
    SQL> create table t1 (a varchar2(1));
    Table created.
    SQL> create table t2 (aa varchar2(1));
    Table created.
    SQL> select a aa from t1
      2  union
      3  select aa from t2
      4  order by aa;
    no rows selectedDid you see how we nicely could order by the column name of the second select? NOT! It's because of the column alias. Look at the next select
    SQL> select a aa from t1
      2  union
      3  select aa from t2
      4  order by a;
    order by a
    ERROR at line 4:
    ORA-00904: "A": invalid identifierDid you see, that the column name of the first select is not valid as there is a column alias?
    That's why the best is, to use result set numbers when ordering in unions
    SQL> select a aa from t1
      2  union
      3  select aa from t2
      4  order by 1;
    no rows selected
    SQL> Edited by: Leo Mannhart on Mar 6, 2009 10:37 AM
    And that's why the columns in the order by MUST be in the select list. Another error in the original post

  • UNION changes type of field

    Statement 1:
    SELECT E0380.CardValue
    FROM (SELECT E0465.CardValue FROM E0465 UNION ALL
    SELECT null AS CardValue FROM E0465) E0380
    Statement 2:
    SELECT E0465.CardValue FROM E0465
    I use OleDbCommand to execute these 2 statements. For statement 1 I use GetDecimal method to get value.
    For statement 2 I use GetDouble to get value. The type of field CardValue is FLOAT. Why the type in these 2
    statements are different? How to solve this problem?
    My Oracle is 10g and connection string is "Provider=OraOLEDB.Oracle;Data Source=EMS;Password=abc;User ID=S000"
    Thanks a lot
    Edited by: user1095915 on May 8, 2012 10:59 AM

    I believe the behavior you're describing is apparent outside of OLEDB, so the database sql forum may be better equipped to assist.
    I tested the following, so we could easily see the resulting datatype from the union:
    SQL> create table floattab(col1 float);
    Table created.
    SQL> SELECT E0380.col1
      2  FROM (SELECT floattab.col1 FROM floattab UNION ALL
      3  SELECT null AS CardValue FROM dual) E0380;
          COL1
    SQL> create table tt as SELECT E0380.col1
      2  FROM (SELECT floattab.col1 FROM floattab UNION ALL
      3  SELECT null AS CardValue FROM dual) E0380;
    Table created.
    SQL> desc tt;
    Name                                      Null?    Type
    COL1                                               NUMBER
    SQL> desc floattab;
    Name                                      Null?    Type
    COL1                                               FLOAT(126)
    SQL>If I read the docs correctly, it looks like this is probably expected, but the database folks may be able to comment better since the behavior does not seem related to OLEDB.
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries004.htm
    Hope it helps,
    Greg

  • SQL Query Using Join

    Hi,
    I am trying to join two tables using joining.
    SQL> select * from test10;
    ID
    1
    2
    SQL> select * from test11;
    ID
    1
    3
    4
    My expected output is
    ID
    1
    2
    3
    4
    I am able to do this using "Union"
    SQL> select * from test10
    2 union
    3 select * from test11;
    ID
    1
    2
    3
    4
    But i want to achieve this using join. Please help..
    Thanks & Regards,
    Arijit

    Hi, Arijit,
    The way to do that with a join is FULL OUTER JOIN, like this:
    SELECT       NVL (t10.id, t11.id)     AS id
    FROM               test10  t10
    FULL OUTER JOIN  test11  t11  ON   t10.id  = t11.id
    ORDER BY  1
    ;If that's exactly what you're trying to do, you should stick with the UNION.
    FULL OUTER JOIN is good when there are other columns involved.

  • Performance Tuning Issues: UNION and Stored Outlines

    Hi,
    I have two questions,
    Firstly I have read this:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_1016.htm#i35699
    What I can understand is using UNION ALL is better than UNION.
    The ALL in UNION ALL is logically valid because of this exclusivity. It allows the plan to be carried out without an expensive sort to rule out duplicate rows for the two halves of the query.
    Can someone explain me the following sentences.
    Secondly my Oracle Database 10g is on FIRST_ROWS_1, how can stored outlines help in reducing I/O cost and response time in general?Please explain.
    Thank you,
    Adith

    Union ALL and Union
    SQL> select 1, 2 from dual
    union
    select 1, 2 from dual;
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 2 | 6 (67)| 00:00:01 |
    | 1 | SORT UNIQUE | | 2 | 6 (67)| 00:00:01 |
    | 2 | UNION-ALL | | | | |
    | 3 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
    | 4 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
    11 rows selected.
    SQL>select 1, 2 from dual
    union all
    select 1, 2 from dual;
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 2 | 4 (50)| 00:00:01 |
    | 1 | UNION-ALL | | | | |
    | 2 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
    | 3 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
    10 rows selected.
    Adith

  • BO Edge 3.1 run Crystal Report with sub query or Union

    I have some reports with subquery and union SQL Command and put them in SAP BO Edge 3.1 server. The results are very disappointed. I scheduled 3 instances of the same report to run at 5:30 a.m. . When I used the Crystal Report 2008 to run the report, it took only 3 minutes. One instance took several minutes but other two never came back. When I came back to the office at 8:30 a.m., they were still running. What is the problem with SAP BO Edge? Any solution? the reports are very important and I have to get up at 5:30 a.m. to check to see the result and re run as needed. Any suggestion?
    Thanks.

    Look at the errors in each instance to help determine the cause

  • Integrating the two parts of a union select statement...

    Hi everybody ,
    I have a query such as the one follows...:
    SELECT TMHMA , DATES , COUNT(EXETASI)
    FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
    WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
    GROUP BY TMHMA , DATES
    UNION
    SELECT TMHMA , DATES , SUM(NUM_TESTS)
    FROM NUM_TESTS_PROFILE ,
    PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
    WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
    PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
    GROUP BY TMHMA , DATES
    Is this possible to integrate the two parts of the above union sql statement into one (without using union) and compute the result of COUNT(EXETASI)+SUM(NUM_TESTS)..????
    Thanks , a lot
    Simon

    Hi , Jameel
    it is not correct because the columns more than one table has the columns TMHMA and DATES . To indicate this , i rewrite the query...
    SELECT PAR_TESTS_MS.TMHMA , PAR_TESTS_MS.DATES , COUNT(EXETASI)
    FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
    WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
    GROUP BY TMHMA , DATES
    UNION
    SELECT PAR_PROFILE_MS.TMHMA , PAR_PROFILE_MS.DATES , SUM(NUM_TESTS)
    FROM NUM_TESTS_PROFILE ,
    PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
    WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
    PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
    GROUP BY TMHMA , DATES
    and the results
    TMHMA DATES COUNT(EXETASI)
    11 19/8/2005 1
    11 15/9/2005 4
    11 15/9/2005 57
    11 16/9/2005 58
    11 10/10/2005 4
    11 10/10/2005 72
    11 14/10/2005 3
    11 14/10/2005 160
    11 7/4/2006 2
    11 7/4/2006 53
    11 8/4/2006 2
    11 8/4/2006 61
    11 9/4/2006 2
    11 9/4/2006 31
    209 30/4/2006 3
    209 30/4/2006 31
    209 8/5/2006 4
    209 8/5/2006 31
    88 20/10/2005 2
    88 20/10/2005 59
    and the expected results.....
    TMHMA DATES COUNT(EXETASI)
    11 19/8/2005 1
    11 15/9/2005 61
    11 16/9/2005 58
    11 10/10/2005 76
    11 14/10/2005 163
    11 7/4/2006 55
    11 8/4/2006 63b]
    11 9/4/2006 [b]33
    209 30/4/2006 34
    209 8/5/2006 35
    88 20/10/2005 61
    Thanks , a lot
    Simon

Maybe you are looking for

  • Conflicting information about external display resolution - please help!

    I have a MacBook Pro (15-inch, Mid 2009) with the non-reflective screen, Mini Display Port and NVIDIA GeForce 9400M Graphics processor. According to these technical specifications (http://support.apple.com/kb/SP544), the built-in NVIDIA GeForce 9400M

  • Copypaste from Illustrator to PowerPoint doesn't work correctly

    This problem has never been in CS6, it is only in the CC When I past an object from Illustrator CC to PowerPoint I see unexplaned code: Please help!

  • Unable to load console information!!!!

    hi, i installed the SunMC agent on server2 and i have already installed the SunMC server on server1 and i assigned the server1 to be SunMC server for the agent of the server2. but when i run "Discover Objects" from my domain , it catch the server2 bu

  • Best way to work with AVI

    Hi there, I am expecting a bunch of Super 8 mm transfert that will be in the AVI format. What is the best way to import the AVI files into FCP in order to get the best quality and edit them ? Thanks in advance Ivan

  • Cellrenderer doesn't refresh upon Scroll

    I'm finding that the only way I can refresh a datagrid containing jpegs, rendered with cellrenderer, is by setting a scroll event on the datagrid, then resizing the column to the same value inside this event's function. Is this a known problem?