query: without the help of the union

Hai, everyone,

IHAVE àtable like this:

Table1:

ID emp1 emp2 emp3
1 100 200 300
2 90 295 977
3 150 299 500




and I need the result like this:

100
90
150
200
295
299
300
977
500



the result is just union emp1, emp2 and emp3

That is to say, this type of result, we can produce with this:

Select emp1 in table1 union select emp2 emp3 union table1 select from table1

but I need a query with the same result as above without using the union statement

Thanks in advance...

Published by: jp_valapad on Sep 12, 2008 02:38

Published by: jp_valapad on Sep 12, 2008 02:39

But the order guaranteed?

N ° as it is never without an order by ;)
But op didn't say anything about a particular order (again)...

Tags: Database

Similar Questions

  • A report from a query using the Union

    Hello. I try to select an account for this request and then to display the total in a message, but I'm getting one too many returned lines (ORA-01422). Can someone tell me how I can get a total for this request?
             SELECT nvl(count(*),0)
           INTO conflict_cnt
           FROM dropper_assign
            WHERE dropper_id = :dropper_vacations.dropper_id AND
                trunc(sched_date) between :begin_dt and :end_dt
              union                           
       SELECT nvl(count(*),0) 
        FROM exfc.bundle a, splits b
        WHERE a.bundle = b.bundle AND
             b.dropper_id = :dropper_vacations.dropper_id AND
             trunc(a.actual_dt) between :begin_dt and :end_dt;
    
              call_alert.the_error('test: '||to_char(conflict_cnt));
    Any help would be greatly appreciated.

    Hello
    first: your Union will always return two rows
    Second: there is no need to put a nvl() because a county will always return o If nothing with the criteria.

    select count(1)
    into v_1
    from table1;
    select count(1)
    into v_2
    from table_2;
    conflict_cnt = v_1 + v_2;
    /* that(s it !*/
    

    Jean-Yves

  • Rewrite the query without a clause EXISTS

    I would like to know another way to write the query without the EXISTS clause below. The main problem is with the inner query not allowing Java Hibernate to cache the results of the query.

    Select max (wt.wtime) wttme
    x wt.
    PIA,
    z g
    where wt.vid = v.vid and
    v.GID = g.gid and
    g.gname = "XXX" and
    not exists (select *)
    x wt1.
    y v1,.
    z g1
    where wt1.vid = v1.vid and
    v1. GID = g1.gid and
    G1.gname = "XXX" and
    (wt1.last_updated < (sysdate-. 0013) or)
    Upper (WT1. Error) '= t'
    )
    )

    z / / DESC;
    Name of Type Null
    GID NOT NULL NUMBER
    GNAME NOT NULL VARCHAR2 (100)
    ACTIVE NON-NULL CHAR (1)
    DATE OF UPDATE_DATE
    UPDATED_BY VARCHAR2 (50)

    GID GNAME UPDATE_DATE ACTIVE UPDATED_BY
    1 XXX Y 6 July 09 14:50:24 Test

    y / / DESC;
    Name of Type Null
    VID NOT NULL NUMBER
    VNAME NOT NULL VARCHAR2 (100)
    GID NOT NULL NUMBER
    ACTIVE NON-NULL CHAR (1)
    DATE OF UPDATE_DATE
    UPDATED_BY VARCHAR2 (50)

    VID VNAME GID UPDATE_DATE ACTIVE UPDATED_BY
    1 ICT 1 Y 6 July 09 14:50:24 Test
    arvato 2 1 O 6 July 09 14:50:24 Test

    / / DESC x;
    Name of Type Null
    VID NOT NULL NUMBER
    NUMBER OF WTIME
    ERROR VARCHAR2 (4000)
    NOT CLOSED NULL CHAR (1)
    LAST_UPDATED DATE

    VID WTIME LAST_UPDATED CLOSED ERROR
    1 65 N N 10 JUNE 09 00:00:00
    2 23 N N AUGUST 10 09 00:00:00

    Ken R says:
    What I would like to have is a query WITHOUT a clause EXISTS and to implement INSIDE logical query * (wt1.last_updated< (sysdate="" -="" .0013)="" or="" upper(wt1.error)='T' )*="" in="" the="" outer="">

    Well have a look at the two queries above then.

  • avoiding the union

    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for HPUX: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    WITH t AS (SELECT 1 id,
                      'A' grp,
                      1 account,
                      'I' TYPE
                 FROM DUAL
               UNION ALL
               SELECT 2,
                      'A',
                      1,
                      NULL
                 FROM DUAL
               UNION ALL
               SELECT 3,
                      'A',
                      2,
                      NULL
                 FROM DUAL
               UNION ALL
               SELECT 4,
                      'B',
                      1,
                      'I'
                 FROM DUAL
               UNION ALL
               SELECT 5,
                      'B',
                      1,
                      NULL
                 FROM DUAL)
    IDGRP   ACCOUNT    TYPE
    1   A 1             I
    2   A     1
    3   A     2
    4    B     1          I
    5    B     1 
    When the account is changed by Group (such as going from account 1, 2) I need an additional line with a kind of R
    I expected results if I use a union
    SELECT ID,
           grp,
           account,
           CASE
              WHEN LAG (account) OVER (PARTITION BY grp ORDER BY id) != account
              THEN
                 'R'
              ELSE
                 TYPE
           END
              TYPE
      FROM t
    UNION 
    SELECT * FROM t;
    ID,GRP,ACCOUNT,TYPE
    1 A 1 I
    2 A 1
    3 A 2 R
    3 A 2,
    4 B 1 I
    5 B 1 
    However, I want to do it without the union
    There is a solution to help connect by clause model or somehting?

    Published by: pollywog on October 29, 2010 11:32

    Published by: pollywog on October 29, 2010 11:38

    Published by: pollywog on October 29, 2010 11:39

    This code will work only, when there is no space in the ID
    This means that every integer between 1,..., n must be there.

    WITH t AS (SELECT 1 id, 'A' grp, 1 account, 'I' TYPE  FROM DUAL UNION ALL
               SELECT 2, 'A', 1, NULL FROM DUAL UNION ALL
               SELECT 3, 'A', 2, NULL FROM DUAL UNION ALL
               SELECT 4, 'B', 1,'I'   FROM DUAL UNION ALL
               SELECT 5, 'B', 1, NULL FROM DUAL)
    --
    --
     select id, grp, account,
              decode(level,1,TYPE,'R')
     from t
     where level in (1,2)
     connect by (prior id=id-1 and prior grp=grp and prior account != account)
     order by id;
    

    result:

    id      grp     acount  type
    -----------------------------
    1     A     1     I
    2     A     1
    3     A     2     R
    3     A     2
    4     B     1     I
    5     B     1     
    

    Published by: hm on 29.10.2010 09:50

  • Is it possible to group several columns individually without the help of the union?

    Hi, if I have a table with a column numebr I want group, for example, sex, nationality, age and I want to present a summary of this kind:

    County group
    10 male
    23 women
    British 19
    14 Irish
    18 10

    ...
    etc.

    Or even better:
    County group
    10 men
    Sex-wife 23
    British Nationaility 19
    14 Irish
    10 to 18 years

    Is it possible without using loads of trade unions? I just want to do the best way and most effective the table involved has > 100 million lines.

    Thank you very much

    Jen :)

    Hey, Jen,

    Here is another way, which could be faster because it does not unpivot data:

    SELECT    CASE  0
               WHEN  GROUPING (gender)       THEN  'Gender'
               WHEN  GROUPING (nationality)  THEN 'Nationality'
               WHEN  GROUPING (age)         THEN 'Age'
           END                    AS label
    ,       COALESCE ( gender
                   , nationality
                 , TO_CHAR (age)
                 )           AS val
    ,       COUNT (*)          AS cnt
    FROM       t
    GROUP BY  GROUPING SETS ( (gender)
                              , (nationality)
                   , (age)
                   )
    ORDER BY  label
    ,            val
    ;
    

    Output, using the data of knapen:

    LABEL           VAL                    CNT
    --------------- --------------- ----------
    Age             25                       2
    Age             30                       2
    Age             40                       2
    Age             45                       2
    Age             50                       2
    Gender          F                        5
    Gender          M                        5
    Nationality     BRITISH                  4
    Nationality     INDIAN                   3
    Nationality     IRISH                    3
    
  • How to get the values in a single line, without the help of the union

    Hello

    I have a table with the structure and the following data

    EmpID address phoneno emailid
    1001 xyz
    1001 1234234
    1001 [email protected]
    1002 23434
    1002 [email protected]
    1003 abcd
    1003 [email protected]
    1004 [email protected]



    I need to get a result in this format.


    EMP id address phoneno emailid
    1001 xyz 1234234 [email protected]
    1002 23434 [email protected]
    1003 abcd [email protected]
    1004 [email protected]


    I can do this by using the union, but who gives a performance of questions with a large table. I want to do it using any other way using lead or something, but with the relative to data complexity, I couldn't do it.

    Can someone help me please?


    Natarajan

    Published by: Nikita on December 3, 2009 15:50
    Select employee_id, max(address), max(phone), max(email)
    from emp
    group by employee_id;
    

    Max

  • Without the help of trade unions

    Is there a way to avoid a union query (which means two full table scans) for the following:

    Here's the whole upward:
    create table x
    (number (2) id,)
    leftid number (5),
    rightid number (5)
    );

    insert into x values (1,11111,11111);
    insert into x values (2,11111,22222);
    insert into x values (3,22222,33333);

    And here's the query:
    SELECT id, leftid, 'left' of x
    Union
    SELECT id, rightid, 'right' of x;


    The paintings that I have are huge and for the performance, I'd rather not have the table read twice, but always get the result set in the union above query... Thank you!
    ID LEFTID SIDE
    ---------- ---------- -----
    1 11111 LEFT
    1 RIGHT 11111
    2 LEFT 11111
    2 RIGHT 22222
    3 LEFT 22222
    3 RIGHT 33333
    SQL> select  *
      2    from  x
      3  /
    
            ID     LEFTID    RIGHTID
    ---------- ---------- ----------
             1      11111      11111
             2      11111      22222
             3      22222      33333
    
    select  id,
            case lvl when 1 then leftid else rightid end sideid,
            case lvl when 1 then 'LEFT' else 'RIGHT' end side
      from  x,
            (select  level lvl
               from  dual
               connect by level < 3
            )
    /
    
            ID     SIDEID SIDE
    ---------- ---------- -----
             1      11111 LEFT
             2      11111 LEFT
             3      22222 LEFT
             1      11111 RIGHT
             2      22222 RIGHT
             3      33333 RIGHT
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • without the use of union or union of all the

    Hello experts

    I have the following data below

    create the table t_me

    (

    first_one varchar (1000).

    second_one varchar (1000).

    third_one varchar (1000).

    week_needed varchar (1000)

    );

    insert into t_me values ('A', 'B', 'C', ' week 1 "');

    insert into t_me values ('A', 'B', 'C', ' week 1 "');

    insert into t_me values ('B', 'B', 'C', ' week 1 "');

    insert into t_me values ('C', 'A', 'C', ' week 2 "");

    insert into t_me values ('C', 'A', 'C', "3 week");

    insert into values of t_me ('B', 'C', 'B', "3 week");

    output desired without the use of union

    the characters first_one, second_one, third_one week_needed

    Week 1             A:                2               0              0

    Week 1             B:               1               3              0

    Week 1             C:               0                0              3

    Week 2             A:               0                1              0

    Week 2             C:               1                0              1

    Week 3             A:               0                 1             0

    Week 3             B:               1                 1              0

    Week 3             C:               1                 0              2

    Any help is appreciated. Thank you

    Hello

    If you want something that works in your version, you should tell what version it is, especially if this version is 12 years old.

    Here's a way to make the unpivot operator and rotate in Oracle 9:

    WITH cntr AS

    (

    SELECT LEVEL AS col_num

    OF the double

    CONNECT BY LEVEL<=>

    )

    unpivoted_data AS

    (

    SELECT week_needed

    col_num

    CASE col_num

    WHEN 1 THEN first_one

    WHEN 2 THEN second_one

    WHEN 3 THEN third_one

    AS END characters

    OF t_me

    CROSS JOIN cntr

    )

    SELECT week_needed, characters

    , COUNT (CASE WHEN col_num = 1, 1 END) AS first_one

    , COUNT (CASE WHEN col_num = END 2 THEN 1) AS second_one

    , COUNT (CASE WHEN col_num = END of the 3 THEN 1) AS third_one

    Of unpivoted_data

    GROUP BY week_needed, characters

    ORDER BY week_needed, characters

    ;

  • Using Clob in the Union query

    Hello everyone, have a look at the statements below and let me know what wrong with my approach.

    CREATE TABLE test
    (column1 CLOB);
    
    
    INSERT INTO test 
    SELECT to_clob('This is test') FROM dual;
    

    When I run the query below, I get data types incompatible error (ORA-00932). Help, please.

    SELECT to_clob('This is test two') FROM dual 
    UNION
    SELECT column1 FROM test;
    

    Kind regards

    Shiva.

    Hey Shiva,

    Copied from documentation

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/queries004.htm

    Restrictions on operators define the set operators are subject to the following restrictions:

    • Set operators are not valid on columns of type BLOB , CLOB , BFILE , VARRAY , or a nested table.
    • The UNION , INTERSECT , and MINUS operators are not valid on LONG columns.
    • If the selection list prior the operator set contains an expression, you must provide an alias for the expression column to refer in the order_by_clause .
    • You cannot specify also the for_update_clause with the set operators.
    • You cannot specify the order_by_clause in the subquery of these operators.
    • You cannot use these operators in SELECT statements containing the TABLE expressions collection.
  • Help! 'Submit query' in the Send button?

    Hello! ... Please see the "Submit Query" message inside my button "submit" below

    How can I get rid of him? ... or is there a code error?... I can't find it... check the code below

    Screen Shot 2013-11-12 at 2.16.58 PM.png

    < do action = "/ FormProcessv2.aspx?" WebFormID = 65717 & amp; OID = {module_oid} & amp; OTYPE = {module_otype} & amp; EID = {module_eid} & amp; CID = {module_cid} & amp; SAR = false PageID = 10857312 "enctype =" multipart/form-data"onsubmit ="return checkWholeForm27006 (this)"method ="post"name ="catwebformform27006"autocomplete ="off">

    < table cellspacing = "0" cellpadding = "0" border = "0" >

    < tbody >

    < b >

    < style td = "" width: 300px; "> < label ="First name"ID = 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> name < span class ="req"> * </span > < / label > < br / >"

    < input type = "text" maxlength = "255" class = "cat_textbox" id = "First name" name = "FirstName" / > < table >

    < style td = "" width: 50px; ' > < table > "

    < style td = "" width: 300px; "> < label ="As WorkPhone"ID = 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> business phone number < / label > < br / >"

    < input type = "text" maxlength = "255" class = "cat_textbox" id = "As WorkPhone" name = "As WorkPhone" / > < table >

    < /tr >

    < b >

    < td colspan = "3" > < table >

    < /tr >

    < b >

    < style td = "" width: 300px; "> < label ="LastName"ID = 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> name < span class ="req"> * </span > < / label > < br / >"

    < input type = "text" maxlength = "255" class = "cat_textbox" id = "LastName" name = "LastName" / > < table >

    < style td = "" width: 50px; ' > < table > "

    < style td = "" width: 300px; "> < label = id of 'Society' = 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> company < / label > < br / >"

    < input type = "text" maxlength = "255" class = "cat_textbox" id = "name" = "Company" / > < table >

    < /tr >

    < b >

    < td colspan = "3" > < table >

    < /tr >

    < b >

    < td > < label = "EmailAddress" ID = 'label' class = "fld-label actAsDiv contactform grpelem clearfix" > E-mail address < span class = "req" > * </span > < / label > < br / >

    < input type = "text" maxlength = "255" class = "cat_textbox" id = "EmailAddress" name = "EmailAddress" / > < table >

    < style td = "" width: 50px; ' > < table > "

    < style td = "" width: 300px; "> < table >"

    < /tr >

    < b >

    < td colspan = "3" > {module_ccsecurity} < table >

    < /tr >

    < / tbody >

    < /table >

    < table cellspacing = "0" cellpadding = "0" border = "0" >

    < tbody >

    < b >

    < td colspan = "4" > < table >

    < /tr >

    < b >

    < style td = "" width: 300px; "> < label ="CAT_Custom_334760"ID = 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> how did you hear about us: < / label > < br / >"

    < select class = "form cat_dropdown" id = "CAT_Custom_334760" name = "CAT_Custom_334760" >

    "< option value =" ">--please select--< / option >".

    < option value = "Colleague" > fellow < / option >

    < option value = "Search" > Search online < / option >

    < option value = 'LinkedIn' > LinkedIn < / option >

    < option value = "Puts a demonstration" > met at an event < / option >

    < / select > < table >

    < style td = "" width: 50px; ' > < table > "

    < style td = "" width: 20px; "> < input type ="checkbox"value ="1"id ="CAT_Custom_334761"name ="CAT_Custom_334761"/ > < table >"

    < style td = "" width: 280px; ">"

    < label ID = "CAT_Custom_334761" = 'label' class = "fld-label actAsDiv contactform1 grpelem clearfix" > add me to your email list < / label > < table >

    < /tr >

    < b >

    < td colspan = "4" > < table >

    < /tr >

    < b >

    < style td = "" width: 650px; "colspan ="4"> < label ID ="CAT_Custom_334762"= 'label' class ="fld-label actAsDiv contactform grpelem clearfix"> how can I help: < / label > < br / >"

    < textarea onkeydown = "if (this.value.length & gt; = 4000) this.value = this.value.substring (0,3999);" class = "cat_listbox contactform1" rows = "4" cols = "10" id = "CAT_Custom_334762" name = "CAT_Custom_334762" > < / textarea > < table >

    < /tr >

    < b >

    < td colspan = "4" > < table >

    < /tr >

    < b >

    < style td = "" width: 650px; "colspan ="4"> < input type ="submit"id ="catwebformbutton"class ="cat_button u4433-17"/ > < table >"

    < /tr >

    < / tbody >

    < /table >

    "< script type =" text/javascript"src="/CatalystScripts/ValidationFunctions.js "> < / script >

    < script type = "text/javascript" >

    <! [CDATA]

    var submitcount27006 = 0; function checkWholeForm27006 (theForm) {var why = ""; if (theForm.FirstName) why += isEmpty (theForm.FirstName.value, "Name");} If (theForm.LastName) why += isEmpty (theForm.LastName.value, "Last name"); If (theForm.EmailAddress) why += checkEmail (theForm.EmailAddress.value); If (why! = "") {alert (why);} return false ;} If (submitcount27006 == 0) {submitcount27006 ++; theForm.submit (); return false ;}; else {alert ("the form submission is in course."); return false ;}}}}

    []] >

    < /script >

    < / make >

    text-indent:-9999px;

    OR better if you switch you can style just pure CSS and stationary state etc. without the use of images.

  • Alternative and improvement of the union query?

    Hello

    I have 2 sets of similar data together with a union query.

    Simplified example
    *Table A*
    Name Dept
    Ben    1
    Amy   3
    Ken    3
    
    *Table B*
    Name Dept
    Jim    1
    John  2
    Sue   3
    
    select Name, Dept
    from table A
    UNION
    select Name, Dept
    from table B
    I want to do is to ONLY include data from the second part of the union query, where it is associated with the first part of the union query data.

    For example
    select Name, Dept
    from table A
    UNION
    select Name, Dept
    from table B
    where Dept in (select distinct Dept from A)
    That's why John, who works in the Dept 2 would not be included in the results.

    Is there a better or more effective way to achieve that my example using the subquery in the where clause?

    Thank you very much
    Hazel

    Hi, Hazel,

    What you posted is as good as you can get without changing tables.

    Do not say SEPARATE in the IN-under-query:

    ...
    where   Dept in (  select  Dept
                       from    A
                    )
    

    will get the same results, maybe a little faster.

  • When you type a query in the bar always double the third letter, for example, research, if I want to write a 'youtube' written "youutube" what to do, help

    When you type a query in the bar always double the third letter, for example, research, if I want to write a 'youtube' written "youutube" what to do, help

    Hello chilli.willi, try Firefox Safe Mode to see if the problem goes away. Firefox Safe mode is a troubleshooting mode that temporarily disables hardware acceleration, restores some settings and disables add-ons (extensions and themes).

    If Firefox is open, you can restart Firefox Safe mode in the Help menu:

    • Click the menu button

      click Help

      then select restart with disabled modules.

    When the Firefox Safe Mode window appears, select "start mode safe."

    If the problem is not present in Firefox Safe Mode, your problem is probably caused by an extension, theme or hardware acceleration. Please follow the steps described in the section Troubleshooting extensions, themes and problems of hardware acceleration to resolve common Firefox problems to find the cause.

    To exit safe mode of Firefox, simply close Firefox and wait a few seconds before you open Firefox for normal use again.

    When find you what is causing your problems, please let us know. This might help others with the same problem.

  • How Downgrade of El Capitan in Yosemite without data loss and without the help of a Time Machine?

    I, are looking for an answer to this question, but couldn't find one.  If there is an and missed it, please tell me and I will look happily on it.  I want to do it without the help of a Time Machine, because I used it at the time of Yosemite.  And I discovered that you can use a cable USB or SD to come down, but how do you do this without losing all my data?

    You must save, erase the drive, install Yosemite, restore your backup of the data

  • Corrupt mail? My new gmail address mail went down fine. Then I lost a large part of it in the box in. Sent mail seems to reproduce several times in my project. Also in the trash without my help. Help appreciated. Thank you.

    Corrupt mail?

    My new gmail address mail went down fine. Then I lost a large part of it in the box in.

    Sent mail seems to reproduce several times in my project. Also in the trash without my help. Help appreciated. Thank you.

    Yosemite of OS X running.

    Also went to Applications > utilities, disk utility. and 'Repair permissions' restarted when finished. Don't know if this will help future emails.

    To project e-mails, open the preferences Mail account tab select the account gmail and go to the behaviour of the ball. Uncheck the tab where you will store draft messages on the server.

    Give a little more detail on other issues. For the lost emails, they lack also the site of the gmail webmail?

  • I offered him my iPad to my father, and it was forgotten not only apple ID, but also by e-mail. the ipad needed to activate the icloud since its ios 9.3 update. You can help me to unlock the ipad without the iCloud. I have evidence to prove that it's mine

    I offered him my iPad to my father, and it was forgotten not only apple ID, but also by e-mail. the ipad needed to activate the icloud since its ios 9.3 update. You can help me to unlock the ipad without the iCloud. I have evidence to prove that it's mine

    You need to take it to an Apple Store with a dated receipt to prove that you are the original owner/purchaser. It's possible Apple may be able to release the lock. We can not help you with it.

Maybe you are looking for

  • Firefox can't find the server, a problem before.

    I have a folder in my yahoo mail named bmd, when I click it rises, but firefox says that it can't find the server. I have been using this website for months with no problems. It is a legitimate site for unwanted ancestry certificates.It does not eith

  • How can I disable private browsing for the high school students on the school laptops?

    Hello, I work for a school district and one of the schools in the district is a digital Academy, which means that students work completely with laptops. The grade level of the students ranged from grade 6 to grade 12. We must be able to install pulgi

  • SharePoint 2003 - Web site

    I was recently put to the challenge of building a Web site to improve communications in my division of labor. My system currently has Microsoft SharePoint Server 2003 load. I plan to build a Web site using Sharepoint Designer and I was wondering if i

  • track 10 seconds mp3

    OK, I want to have a nice little utility that will reduce from 10 or so seconds of the song in the middle and add it to the front of the file of the song. the reason why I want it is because I want the quick little song before starting to listen to h

  • STATUS. ERROR MESSAGE AFTER HP PRINTER SOFTWARE DOWNLOAD-WINDOWS XP UPDATE MSI

    I tried to install my Hp Deskjet F4180 and kept getting this error message "Error 1603" (MSI) went to the center of the HP Solution and follow all the instructions which have been described, but the same error message comes back. Can someone help me