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

Tags: Database

Similar Questions

  • 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
    
  • In the electronic-search mail there is no possibility to show a column with the number of attachments has the e-mail found. I googled for solutions: sick only ideas!

    Examle: I looking for a piece attached to a particular sender - in 3 seconds I with the thunderbird electronic-mail-search a list with all the messages from the special sender, but I do not see what emails contain attachments. If I could choose the column 'number of attachments' it would be useful: 0 = there is no attachment, it is foolish to click and open it: 1) I have to close this bad-opend-window and 2.) I return to the search results window because now I'm in the thunderbird main display. Some companies still send their logo like attachment = no problem: once I opened an e-mail-results of research I can see: oh, they always send a logo, so I have to search for emails with attachments 2 and so on. (Please excuse the word "sick" in my question: I'm not very good in English, the line was so short, and I did not know that I can write the details too.)

    Try this add-on: http://attachmentcount.mozdev.org/index.html

  • Show a column with a list of the DOUBLE values;

    Hello, how to display something like:

    COL1
    -------
    A
    B
    C
    D
    E
    F

    drbiloukos wrote:
    ORA-00904: "REGEXP_REPLACE": invalid identifier
    00904, 00000 - '% s: invalid identifier '.
    * Cause:
    * Action:
    Error on line: column 132: 28

    I'm on 9i

    Really? I've seen that mentioned anywhere before. How everybody had to know that you are using an older version of the database does not support?

    In any case...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'I Need a List with Words not Letters' as txt from dual)
      2  --
      3  select substr( txt
      4               , decode(level, 1, 1, instr(txt, ' ', 1, level-1)+1)
      5               , decode(instr(txt, ' ', 1, level), 0, length(txt), instr(txt, ' ', 1, level)
      6                 - decode(level, 1, 0, instr(txt, ' ', 1, level-1))-1)
      7               ) val
      8  from t
      9* connect by level <= length(txt)-length(replace(txt,' '))+1
    SQL> /
    
    VAL
    ------------------------------------
    I
    Need
    a
    List
    with
    Words
    not
    Letters
    
    8 rows selected.
    
    SQL>
    
  • Needs of report to show all columns

    Hello, I have two interactive reports on two different pages, and I'm unable to show all columns. It will automatically appear all the columns. I know that I can show them all with Actions / Select the columns / > >, but I can't expect all of my users to do each time that they reopen the browser. They want that search the IRs without pressing Actions each time.

    In my 1st report, I just a column of money, but it will not appear automatically. How can I get the GAL_PUMPED to automatically display column without using the Actions menu each time?

    SELECT UFT.SITE_NUM, UFT.TANK, UFT.FUEL_TYPE, sum(UFT.GALLONS) GAL_PUMPED
    FROM  futrak.FUEL_TRANSACTIONS  UFT
    WHERE to_char(UFT.TRAN_DATE,'MON-YYYY') < to_char(SYSDATE,'MON-YYYY')
    GROUP BY UFT.SITE_NUM, UFT.TANK, UFT.FUEL_TYPE
     

    In my 2nd report, only columns of fth automatically, will not display the columns of ftd. How all the columns in the two tables to automatically display without the Actions menu each time? Also, the unit is supposed to be the last column, but this problem makes the 3rd column after using select columns. I'm stuck with APEX 4.0 and may not use plugins, but I want to hack everything that will help solve this problem. I'd appreciate any help or advice, thank you.

    SELECT fth.SITE_NUM, fth.TANK, sum(ftd.GALLONS), ftd.FLEET_ID, ftd.EXPENSE_TO_PROJECT, ftd.EXPENSE_TO_TASK, fth.UNIT_NUM
    FROM FUEL_USAGE_HEADER fth,
      FUEL_USAGE_DETAIL ftd
    WHERE 
      fth.FUEL_USAGE_ID = ftd.FUEL_USAGE_ID
    AND fth.PROCESSED_DATE is null 
    AND to_char(fth.TRANSACTION_DATE,'MON-YYYY') < to_char(SYSDATE,'MON-YYYY')
    GROUP BY fth.SITE_NUM, fth.TANK ,ftd.FLEET_ID, ftd.EXPENSE_TO_PROJECT, ftd.EXPENSE_TO_TASK, fth.UNIT_NUM
    order by 1
     

    Display all Columns.png

    Login to your application as a developer when running. Modify the report in the way that your users need. Save the report, select "default report parameters.

  • My iphone shows no service with all networks in Egypt also sometimes works and all this happened all of a sudden

    My iphone shows no service with all networks in Egypt also sometimes works and all this happened all of a sudden

    If your provider supports iPhone

    I'd look for an update to the carrier

    Settings - carrier - it will pop up if available

    And if there is none then speak to the carrier a replacement of the SIM card

  • I work with dreamweaver cs6 running on Apple Mavericks.  The site definition window shows all different fields by opening. I have to click blind with the mouse cursor in this window until the fields appear.  It is a very bored

    I work with dreamweaver cs6 running on Apple Mavericks.

    The site definition window shows all different fields by opening. I have to click blind with the mouse cursor in this window until the fields appear.

    It is somehow very annoying to complete the connection to the server and all the other things.

    Is there a solution?

    If this is the case, I think that it is perhaps a good idea to uninstall Dreamweaver. Before you reinstall, make sure that your personal configuration file has been deleted (see reinstalling Dreamweaver (or the extensions Manager) fails to solve problems). You should then have a completely clean copy of Dreamweaver has again the default settings of the program.

  • 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

    ;

  • 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;
    
  • By selecting "Show all bookmarks" show all bookmarks

    Selection of bookmarks in Firefox produces a drop-down list of my favorites. By selecting "Show all bookmarks" in this menu is no longer produces a page with all my favorites. A call of 'Library' page with only a few items happens. This change took place recently. Selecting the icon of the bookmarks at the top right in Firefox also displays a drop-down list of all my favorites.

    There are three broad categories of bookmarks:

    • Bookmarks menu
    • Bookmarks Toolbar
    • Other favorites (previously called Unsorted Bookmarks, I think)

    When you open the Library dialog box by using "Show all bookmarks" or Ctrl + Shift + b, it opens in this third category. To select a different category, use the diagram 'tree' in the left column.

    Who works on your Firefox?

  • How can I show all the results returned by a sql query?

    Hi guys,.

    I need your help.
    Let's say I have a table: TableA. Fields in TableA are aleg, anon, monkeys. The following sentence can return, in general, several rows: select anon from TableA where aleg = somevalue. I would like to show the result of the anon column but no luck. If I try to display the results in a TextArea and the origin is a sql query shows that the first value of the line. I tried to see the like: display text (based in PLSQL) and a block anonymous plsql and coding
    DECLARE
    v_anon TableA.anon%TYPE;
    CURSOR v_cur IS
    Select anon from TableA where aleg = somevalue;
    BEGIN
    OPEN v_cur.
    LOOP
    SEEK v_cur INTO v_anon;
    EXIT WHEN v_cur % NOTFOUND;
    : FIELD_IN_FORM: = v_anon;
    END LOOP;
    CLOSE V_cur;
    END;
    but in this case, he showed no results.
    So the first question is what type of field can I use to show the result. And the second is what can I do to be able to show all the results returned by the query (if more than one line).

    concerning

    GMC

    We are all happy that you found a solution, but you must sign your messages and change your ID forum. It is always good to know the real name of the person you are communicating with. In addition, if you plan to get answer to your questions in the future, you must mark responses as useful or correct if they helped you solve your problems.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    -------------------------------------------------------------------

  • The search for bookmarks in the library "Show all bookmarks": output is missing an * important * thing...

    (1) open a library "show all bookmarks".
    (2) search for any article you know is there, but you don't know where he is among the Favorites.
    3) click on any element in the resulting list.
    (4) you will see a lot of information about the item (bookmark), you clicked on.

    What you want * NOT * see is this very important piece of information: the LOCATION IN THE LIBRARY OF THIS BOOKMARK.

    Where this bookmark is placed in the library? In what folder/subfolder?

    I invite the developers of FireFox to add this info. Please...

    Thank you!

    There is an add-on for this:

    https://addons.Mozilla.org/firefox/addon/show-parent-folder/

    After installation and activation of the extension, Parent folder must appear on the list of columns in the Library dialog box.

    If you want to see the full hierarchy the bookmark rather that just the name of the folder, you can set the page modules. Either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Find show Parent folder on the right, then click on the Options button.

    Note: The extension was created more than 7 years ago and he's still not a built-in feature, so please don't hold your breath!

  • Since worm 36 and perhaps earlier, I have bookmarks under the stars, but not when I ask to show all bookmarks

    by clicking on the bookmarks on the home page gives me my favorites
    I have bookmarks under recently and unsorted bookmarks. I can move from these categories to the master list without problem.
    When I click on show all bookmarks that I get none. He goes to this screen but shows no Favorites.
    I would use these bookmarks on another computer, but also change in show all.

    second problem, my norton toolbar does not load and has not since worm 36

    When you click View all bookmarks to launch the dialog box library, normally, you see three categories listed on the right side. If you double-click in any of the categories, you will find actual bookmark listed there or empty each category?

    To transfer bookmarks in Firefox on another computer, there are two different file formats. I suggest to create two in case one does not work:

    Symantec is usually very quick with updates to date, but it might be a little early for 40 of Firefox (beta version). There is a release supporting 39 Firefox: https://community.norton.com/en/blogs.../firefox-39-support-norton-toolbar. Users report that you sometimes have to run LiveUpdate several times to get the last toolbar into Firefox.

    If you had accidentally on the way to the beta and prefer to have the support of Norton toolbar in good time, you can install the retail version (39 Firefox) and it should work seamlessly with your existing settings.

    It wouldn't hurt to do a backup first. You can find suggestions in this article: back up and restore the information contained in the profiles of Firefox.

    Then do the restore:

    Clean reinstall it

    We use this name, but it isn't about deleting your settings, this is to ensure that the program, files are clean (not incompatible, corrupt or exotic code files). As described below, this process does not disrupt your existing settings. Don't uninstall NOT Firefox, that does not need.

    (1) download a fresh Installer for Firefox 39.0 of https://www.mozilla.org/firefox/all/ in an ideal location. (Scroll down your preferred language).

    (2) close Firefox (if applicable).

    (3) to rename the program folder, either:

    (Windows 64-bit folder names)

    C:\Program Files (x86)\Mozilla Firefox
    

    TO

    C:\Program Files (x86)\OldFirefox
    

    (Windows 32-bit folder names)

    C:\Program Files\Mozilla Firefox
    

    TO

    C:\Program Files\OldFirefox
    

    (4) run the installer you downloaded in the #1. It should automatically connect to your existing settings.

    You can get to the Options page?

    Note: Some plugins can only exist in this OldFirefox file. If it is missing something essential, present in these files:

    • \OldFirefox\Plugins
    • \OldFirefox\browser\plugins
  • Bookmarks do NOT open in a browser window click on the "show all bookmarks".

    Currently using Firefox 30.0.3 Mac OS 10.9.5. When I tried to modify my collection of bookmarks buy opening the "show all bookmarks" in the drop down menu, nothing happened. Usually, this opens a new tab or window with bookmarks is displayed. Then I searched HELP and tried all the solutions without success. Where the topic of aide said even a Bookmarks window will open, this isn't. I have no way to edit or delete massively outdated bookmarks. Yes, I can do so individually through the bookmark button in the toolbar - what a pain in the ___s.

    Is - this problem is intentional or a glitch?

    Good to hear. Several users have reported problems with
    multiple monitors.

    Please report your last post as solved if others
    will know.

  • Double click on the Bookmarks button to open the library window directly ("Show all bookmarks" feature)

    I have a number of folders in the bookmarks, and I frequently change it by clicking on "Show all bookmarks" and by opening a library.
    Earlier, after you click the Bookmarks button, "show all bookmarks" appeared on the top of the list, and now he's down.
    Please, add a double-tap on the Bookmarks button function so that it opens the window of the library directly.

    You can ask for a bug to get this feature if nobody has already done it. But change will have been carefully studied, and it is unlikely to be reversed.

    What you could also do, is add a comment with your feedback

    If you want to return to a mote of style like Firefox 28 or e = earlier consider using addons

    Note We are other users Firefox NO developers and decision makers. Decisions relating to the development and discussion of politics or or feature requests are irrelevant.

Maybe you are looking for

  • How can I change my text color

    Like when I text someone my Green stay cplot are blue

  • Upgrading RAM in HP Media Center PC m7277c

    I have an old HP Media Center PC m7277c with 2 sticks of 512 MB/DDR2 SD RAM. BIOS shows that there are 4 banks of memory - 1 and 3 are busy. I would like the 512 the scrap and upgrade to 4 sticks of 1 GB. My question - my system will support DDR3? If

  • How to turn sound when switching mode sleep?

    Hello I got my 13 edge two days ago and have now installed all updates and upgrade the BIOS (how can this amount of updates it will take a new PC? Not surprised a lot of people have problems with their computers...) But I can't find out how to make t

  • I have a Compaq Presario V5000 Laptop and have lost the files in c: drive recovery...

    I bought this computer laptop opportunity (Compaq Presario V5000), complete with the XP Home installed, which also had the original Preload / recovery facilties installed on the c: drive. and the image of preload on the partition fat32 D: I discovere

  • Adobe Illustrator & Photoshop files appear extremely dark

    I am a graphic designer and photographer. I have Windows Vista Ultimate Edition, Version 6 (Build 6002: Service Pack 2). I use Adobe Illustrator CS4 and Photoshop CS4 to edit my photos. Thumbnails look good, but when you open a file, the picture is r