Values in the list by the order of table in SELECT Union

Version: 11.2

Apparently a very basic thing. But I couldn't do it :)

In the UNION example below automatic sorting in is based on alphabetical order. I want to get rid of this sort and list the values according to the order of the table in the SELECT.

Test data
create table test1 (name1 varchar2(10));

create table test2 (name2 varchar2(10));

create table test3 (name3 varchar2(10));


insert into test1 values ('EARTH');
insert into test1 values ('TAURUS');
insert into test2 values ('YELLOW');

insert into test2 values ('ALPHA');
insert into test2 values ('TANGO');


insert into test3 values ('BRAVO');


select name1 from test1
union
select name2 from test2
union
select name3 from test3;

NAME1
----------
ALPHA
BRAVO
EARTH
TANGO
TAURUS
YELLOW

6 rows selected.
In the above example, I want the values in the first array SELECT listed first, then all the values of the second table in SELECT it and so on.

Basically my requirement will be
Return all values from test1 (alphabetically sorted)
then
Return all values from test2 (alphabetically sorted)
then
Return all values from test3 (alphabetically sorted)
Expected results:
NAME1
----------
EARTH  ------------> from the first table in the SELECT
TAURUS ------------> from the first table in the SELECT
ALPHA  ----------------------> from the second table in the SELECT
TANGO  ----------------------> from the second table in the SELECT
YELLOW ----------------------> from the second table in the SELECT
BRAVO  ------------------------------> from the third table in the SELECT

Hello

Union made a distinct in terms of the line. From the line "ALPHA", 2 and the line 'ALPHA', 3 are different, they both show in the result set.

Further, you are all just lucky, that you get the results you want with the order clause:

order by 2

This performs a sort on the second column (1,2,3)
Also, you want to sort on the first column (name1, name2 and Name3). The order clause should be (as already shown correctly abbove):

order by
  2, 1

Kind regards

Peter

Tags: Database

Similar Questions

  • How to change the order for table?

    I use oracle 10g 10.2.0.3.0

    I have a select statement
    SELECT /*+ leading v.Guest_Info v.Guest_Domain_Relation Guest_Address*/
    *
      FROM (SELECT 
             Cdr.Guest_Domain_Relation_Id,
             Ci.Guest_Id        
              FROM Guest_Info         Ci,
                   Guest_Domain_Relation Cdr
             WHERE Ci.Guest_Id = Cdr.Guest_Id) v,
           Guest_Address Ca
     WHERE v.Guest_Id = Ca.Guest_Id;
    and explain the Plan shows
    1     Plan hash value: 3785964411
    2      
    3     ---------------------------------------------------------------------------------------------------------
    4     | Id  | Operation                     | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
    5     ---------------------------------------------------------------------------------------------------------
    6     |   0 | SELECT STATEMENT              |                         |  1806 |   199K|     9  (23)| 00:00:01 |
    7     |*  1 |  HASH JOIN                    |                         |  1806 |   199K|     9  (23)| 00:00:01 |
    8     |   2 |   MERGE JOIN                  |                         |   482 | 48682 |     6  (17)| 00:00:01 |
    9     |   3 |    TABLE ACCESS BY INDEX ROWID| Guest_ADDRESS          |   919 | 87305 |     4   (0)| 00:00:01 |
    10     |   4 |     INDEX FULL SCAN           | XAK1Guest_ADDRESS      |   919 |       |     1   (0)| 00:00:01 |
    11     |*  5 |    SORT JOIN                  |                         |   482 |  2892 |     2  (50)| 00:00:01 |
    12     |   6 |     INDEX FULL SCAN           | XPKGuest_INFO          |   482 |  2892 |     1   (0)| 00:00:01 |
    13     |   7 |   VIEW                        | index$_join$_003        |  3493 | 41916 |     3   (0)| 00:00:01 |
    14     |*  8 |    HASH JOIN                  |                         |       |       |            |          |
    15     |   9 |     INDEX FAST FULL SCAN      | XAK1Guest_DOMAIN_Relation |  3493 | 41916 |     1   (0)| 00:00:01 |
    16     |  10 |     INDEX FAST FULL SCAN      | XPKGuest_DOMAIN_Relation  |  3493 | 41916 |     1   (0)| 00:00:01 |
    17     ---------------------------------------------------------------------------------------------------------
    18      
    19     Predicate Information (identified by operation id):
    20     ---------------------------------------------------
    21      
    Is there in any case, I have Guess_Domain_Relation table join firstly that the join to Guess_Address table of Guest_info?

    I tried a few ways to rewrite the query, but he's no luck

    Thank you

    Published by: Y.L on March 20, 2013 13:59

    Y.L wrote:
    And my another problem here... I don't know why my first clue didn't work...

    Probably the syntax. The main indicator uses parentheses, as

    /*+
    select /*+ leading(table1, table2) */ *
      from table1, table2
    */
    

    Remember that you must use the table alias name in tips for the identifier to be recognized

    You can also consider using the y indicator (if you must use a hint) for several tables - beware, it is MUCH easier to do worse performance with this suspicion using the order of the tables in the FROM clause in left to right

    /*+
    select /*+  ordered */ *
      from table1, table2, table3
    . . .
    */
    

    How I create index will affect how it works?

    How the index was created probably won't affect how it works. Indexes can be created using constraints and directly with the CREATE INDEX command. The creation of the index should not be as important as its defined characteristics: index type, columns, etc.

  • Popup2 in SQL don't Report not to the values of the fields in table

    Hi all

    Can someone help me with this instruction box in the pop-up window 2.

    Instead of the values behind the transmitted fields the literal text of 'A.Metric' & 'A.Month' are being passed in the new page instead.

    A.Metric has a value of 10 and A.Month has the value of 1 May 2008.
    ----------------------------------------------------------------------------------------------------------------------
    WHEN PARSING IS NOT NULL THEN
    "< a href ="javascript:popUp2(''e) "
    || ' f ? p = & APP_ID.:305: & SESSION. : & DEBUG. ::'
    || "P305_METRIC_TYPE, P305_METRIC_MONTH:A.METRIC_TYPE, A.MONTH.
    || (', 890, 460); style = "text-decoration: underline;" color: black; do-size: 90% ">"
    || "< img src =" #APP_IMAGES #notes.jpg ">"
    || "< /a >" END "analysis."
    ----------------------------------------------------------------------------------------------------------------------

    Frank

    Well, first of all try with | «, » || So tell me if you have the error, please do - send your entire query (also remove the quotes of the alias of the analysis of the column - they are not mandatory).

    Ben

  • Request to make cases in sensitive order by a statement select union

    Hi all

    I want to perform a case-sensitive by an instruction order select union.

    SELECT SERVICEREQUEST_SYSNO, SERVICEREQUEST_DESC from STHV_PRODUCT_SRTYPE_DETAILS WHERE COUNTRY_CODE = #countryId # AND PRODUCT_DESC = #ProductVal #.
    Union
    Select distinct SERVICEREQUESTTYPECODE, SERVICEREQUESTTYPE from CWFV_RULES_AS ARC, SPM STH_PROCESS_MASTER where COUNTRY_CODE = #countryId # and PRODUCT = #ProductVal # AND SPM.description = ARC. Order lower B_WORKFLOW_NAME (SERVICEREQUEST_DESC)

    the above query gives me error when I order by lower (SERVICEREQUEST_DESC)

    Can someone help me on this.

    Kind regards
    Sandeep.

    One way is below. Why would take you an order, case-insensitive? Not tested.

    select *
    from (
    SELECT SERVICEREQUEST_SYSNO,SERVICEREQUEST_DESC  From STHV_PRODUCT_SRTYPE_DETAILS WHERE COUNTRY_CODE = #countryId# AND PRODUCT_DESC = #ProductVal#
    union
    select distinct SERVICEREQUESTTYPECODE,SERVICEREQUESTTYPE from CWFV_RULES_AS CRA,STH_PROCESS_MASTER SPM where COUNTRY_CODE=#countryId# and PRODUCT=#ProductVal# AND SPM.description = CRA.B_WORKFLOW_NAME
    )
    order by lower(SERVICEREQUEST_DESC)
    
  • Values wrong the way back to a Select list in a pop-up window

    Greetings

    I have a sample application loaded on apex.oracle.com here: http://apex.oracle.com/pls/apex/f?p=54441:3

    Steps to follow:
    1. connect with any ID, there is no authentication
    2 - Select "BATTERSBY DANIELSON & ASSOC" as the Agency
    3 - Select contract ' 1208... "in the drop down menu
    4 - Click on the button "modify an existing contract.
    5 - Click on the button "Create a new constructor" and add what you want to name generator, city and State
    6 - click the 'X' to close the window (cannot do close in itself, but it's another question :-)))

    What I'm trying to take place is the values just placed in the fields "New Builder" to appear in the generator element name on the original page.

    The name of generator comes from the Select list.

    I was able to get the elements of City Builder and generator of State filled but not the name. The name component is actually a concatenation of the Builder and the City Builder name if it is in the Select list or the constructor new pop-up window.

    The new Builder does NOT appear in the list select after his return even though I would only it.

    The process that is executed when you add a new constructor is an INSERT in the table that generates the select list and VALIDATION.

    When a new constructor is added the STATUS column in the table generator is set on "HOLD", so I can identify as a generator again later in the process.

    Any help is greatly appreciated!

    Internal environment is APEX 3.2.1.00.10

    -gary

    I ended up not not using the pop-up as suggests.

    Sometimes the solutions are too easy.

    Thanks for the comments!

    -gary

  • County to assimilate all of the instance of unique value in the drop-down table?

    I'm just a beginner. I know how the code in order to get an automatic count of lines but I try to go a little further.

    I would like to be able to get a number that matches the number of times that a value has been chosen from a drop-down list.

    I have attached a few illustrations to explain what I'm trying to achieve:

    Pic 10.PNG

    In the end, I would like to end up with something like that.

    pic11.PNG

    Any help would be appreciated.

    Hello

    To do something like this, you must use the calculate of the County field event.

    What you want to do is to count how many times the name in the drop-down list is selected up to that line.

    If you use this for loop by using JavaScript and change the names for your form should look like this:

    The parent of the field line

    myRow = this.parent.parent var; Use this line if the field is in the subform

    myRow var = this.parent;

    Number of divers

    var intDiverCount = 0;

    for (var i = 0; i)<= myrow.index;="">

    Store lines in a variable

    preRow var = this.resolveNode ("Row1 [" + I.ToString + "]");

    If the name of the diver is the same selected add 1 to the count of the diver

    If (preRow.ddlDiver.getDisplayItem (preRow.ddlDiver.selectedIndex) is {myRow.ddlDiver.getDisplayItem (myRow.ddlDiver.selectedIndex))}

    intDiverCount ++;

    }

    }

    Number of divers display

    intDiverCount;

    And in FormCalc:

    The parent of the field line

    myRow = this.parent.parent var; Use this line if the field is in the subform

    myRow var = this.parent;

    Number of divers

    var intDiverCount = 0

    for i = 0 upto myRow.index step 1 do

    Store lines in a variable

    preRow var = $.resolveNode (Concat ("Row1 [", i, "]"] ""))

    If the name of the diver is the same selected add 1 to the count of the diver

    If (preRow.ddlDiver.getDisplayItem (preRow.ddlDiver.selectedIndex) eq myRow.ddlDiver.getDisplayItem (myRow.ddlDiver.selectedIndex)) then

    intDiverCount = intDiverCount + 1

    endif

    ENDFOR

    Number of divers display

    intDiverCount

    I hope this helps!

  • Assign the values of the two variables in a select statement

    I'm trying to set two variables in a select statement in my definition of the procedure. I get the error identifier not valid "ATTRIBUTE" running the following code.
    create or replace procedure tbl_auth (
    Email in varchar2,
    UserLevel out number)
    as
      v_Email varchar2(100) := lower(Email);
      v_login_chk number := 0;
    begin
     select UserLevel into p_UserLevel,
            v_login_chk into v_login_chk
     from tbl_User
     where eMail=v_Email  
    
    exception
     when no_data_found then
      UserLevel := 0;
    end tbl_auth;
    Can I not connect two different values to two different variables in the same select?

    Thank you

    Published by: jerry8989 on August 22, 2011 07:06

    Published by: jerry8989 on August 22, 2011 07:06

    change as follows:

     select UserLevel, v_login_chk into p_UserLevel,
            v_login_chk
    

    IN ONE ALONE is enough.

    BTW, don't you have "login Check" column in the "tbl_user"? If you do, your selection should be like this:

    ...
    select UserLevel, loginChk into /* check the column name in your table */
             p_UserLevel, v_login_chk
     from tbl_User
    ...
    
  • How to get the value of the card that is clicked

    Hello

    I work in the apex 5.0 with universal theme.

    I had a type list box.

    Attributes, I chose the cards of value as a list template.

    When someone clicks on the map, it will be redirected to another page. Before that happens, I want to fix an application with the value of the card that has been selected.

    I can't understand how to do this. I tried with dynamic action, but that has not worked.

    Hello

    If I'm not completely wrong and that you set the item asking "Checksum Required - Session-level" we'll automatically the checksum protect your URL and users will not be able to change it manually. Don't forget that with dynamic action that is executed on the client side, you will never be able to change your point of application safely. All dynamic action can can also be done manually by the user. Links with checksum are safe because him are generated server-side.

    Concerning

    Patrick

  • Total of the values of the columns in the adf

    Hello

    I use JDev 11.1.2.4.

    I put in place a total of a column (order amount) in my OrderDetailVO this link posted by ADFInsiderEssentials (to implement a total using Oracle ADF - ADF Essentials Insider)

    http://www.YouTube.com/watch?v=HnxtkInjv6c

    by creating a temporary variable, value TotalAmount defining the expression groovy as OrderDetail1.sum("OrderDetailAmount==null?0:OrderDetailAmount")

    But my requirement is a little different. In fact, I want to save this value in the Order_Header database table.

    I tried to overried Commit method as follows

    ADFUtils.setBoundAttributeValue ("Amount", OrderDetailAmount.getValue ());
    BindingContainer links = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding ("Commit");
    Object result = operationBinding.execute ();

    but I am getting following error when I save the recording a couple of times.

    oracle.jbo.RowInconsistentException: Houston-25014: another user has modified the line containing oracle.jbo.Key [1 primary key].

    any ideas?

    Thank you

    HI Emmar

    so you can go back on the same line, after validation and run

    Blog of Ashish Awasthi (Jdev/ADF): located on the current line after refreshing the page or perform Rollback

    and Yes also think that suggests, Timo Hahn

    Thank you

  • How to display the values of the Parent form in the form of child

    Hello


    I have the order Page and Page element


    In the order Page If I select any item and click submit, it should open the article Page and results should display in advance table region. In my article page I have region of header (default double) with 3 fields (dummy) as

    Agenda
    Description
    org

    Now my question is, I need to display the value of the item in the item Page header area in the column of the item that I was selecting in the order Page.

    I have a prescription 100 point A, B, C, I select B and click on submit it should open on the Articles page and article Page, I have a column called Item and value B sholud be fulfilled.



    Thank you
    Mahesh

    OAMessageTextInputBean oa = (OAMessageTextInputBean) webBean.findChildRecursive ("ItemNo");
    oa.setAttributeValue (SItemNo);

    There is no such method as setAttributeValue for UI beans, this method is for VO, that is to say if you take a VO and VO a method object to set its attribute.

    Bean of the user interface, you will need to use method below,

    OAMessageTextInputBean oa = (OAMessageTextInputBean)webBean.findChildRecursive("ItemNo");
    oa.setValue(pageContext,SItemNo);
    

    Thank you
    AJ

  • Is this bug reports Oracle - 'break the order property' in the report "above.

    Is this bug reports Oracle - 'break the order property' in the report "above.

    Anyone would confirm that in the report 'group above', we could only order the values in the column of brake with ' "nil" or "ascending" or "descending" provided by "pause command property? '"

    In the following example, "Dept" is brake column. Reports Oracle allows the values of the order in 'Dept' with 'descendant' provided by 'pause order property:

    Dept. 30
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    20 DEP.
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    Dept 10
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    or "Crescent" provided by "pause order property:

    Dept 10
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    20 DEP.
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    Dept. 30
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    I have to do:

    20 DEP.
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    Dept 10
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    Dept. 30
    employment ename salary
    xxx xxx xxx
    xxx xxx xxx

    Could I do it? Could someone confirm that we could never do this, or if so, how?

    Million thanks for the advice.

    M.Z.

    Edited by: jielan 18 September 2010 08:23

    Why must be a bug? You have a customs provision and must find a way to fill. But, what is your real sort order? You have only the three departments? If so, you could add a column in your query as

    DECODE(DEPT,  20, 1, 10, 2, 30, 3, 4) SORTING
    

    put this column in the same group as dept and sort after this new column.

  • passing the value of the table to the point

    Hi guys,.

    I have a question about flash cards. I created a Flash (3D Pie) chart and an element. At present the 'link' of this table column is NULL, but now I want to pass the value of the column 'value' to the order of the day, when you click the value in the graph. Does anyone know how this link should be built?
    Hope you understood what I meant... If not let me know and I'll try to explain once again.


    For the moment, it's just like that:
    select  
    NULL LINK,
    s1.STATUS_NAME label,
    (select count(supplier_id) from zf_asn_summary z01 where z01.status_id = z1.status_id) value 
    
    from 
    zf_asn_status s1, 
    zf_asn_summary z1 
    where 
    y1.status_id = s1.status_id
    
    order by s1.status_name
    Thanks and greetings
    Patrick

    How about this one

    select
    'f?p='|| :APP_ID || '::' || :APP_SESSION || '::::PXX_ITEM:'|| value LINK,
    label,
    value
    from
    (select
    s1.STATUS_NAME label,
    (select count(supplier_id) from zf_asn_summary z01 where z01.status_id = z1.status_id) value
    from
    zf_asn_status s1,
    zf_asn_summary z1
    where
    y1.status_id = s1.status_id
    order by s1.status_name)
    
  • get the values of the different acquisition channels

    Hello everyone,

    I finished my project and I want to do something and I did not how. I am acquising three signals from three different pressure sensons with the use of the DAQAssistant configuration to acquire form three analogue ports (there is a screenshot it below) and after it is shown in the same graph (second picture below).

    This works fine, but my problem lies in the fact that I want to measure the maximum value and the value of the minimum pressure of each channel and always it is measured the first of them. I divided the measures in time-slopes as it is shown in the last picture. I have tried every single Vi of part manipulation of the function range signal, but I'm still not in the way of their use or I'm totally wrong actuing in this way.

    Could someone give me a hand?

    Thanks in advance.

    Best regards

    Miguel.

    Really, we do not have enough information to give you good advice, but I can give you some generic advice.  If you want the max and min an array of values, values use the Max & Min table from the palette of Array.  Unfortunately, the DAQ assistant returns the type of dynamic data, which can be either a table of waveforms or waveform unique depending on how you do.  Configuring your DAQ Assistant, it seems you are getting a picture of waveforms, but to use it as a form of single wave.  Just after taking the data, convert your dynamic data type data type in a table using waveforms the DDT express VI in the Express-> palette of data manipulation.  It would probably break a lot of your code, and it's a good thing.  Broken parts are parts that are probably causing you problems.  You can now use the index table to get the individual waveforms to the table and get elements of waveform for the picture of the waveform data.  Use this table with table Max & Min to actually find your max and min values.

    Alternatively, you can use Split Signal of the Express-> palette Manipulation of data to split your output into three unique waveform signals.  Each of these signals can be plugged directly into the table Max & Min (LabVIEW will be script in the necessary converter).  However, I highly recommend that you do NOT.  It leaves you the problem that your data type is not defined yet, as this is always a type of dynamic data.

    Also note that the use of globals as seen in the pictures of your code is a bad habit that can lead to all sorts of problems.  However, I can't offer a lot of advice on how to fix it without the rest of your code (Tip: will probably involve some shift registers).  Please post your screws if you have questions, so we can offer the best advice.

  • Select the column values in the collection

    Greetings,

    I want to select column values from the collection (plsql tables or table), as the following code, would it be possible
    Here tt is any collection



    Select emp_no, name, date of birth, sal tt (1), tt (2), tt (3), tt (4) emp; -single line query

    Select name, Department of justice, strength and dep_no in tt (5), tt (6), tt (7), tt (8) EMP; -single line query


    Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production

    Thanks in advance

    Not sure about your business needs. But technically you can do.

    declare
       type tbl is table of number;
       lemp tbl := tbl();
    begin
       lemp.extend;
       lemp.extend;
       lemp.extend;
    
       select empno
            , mgr
            , sal
         into lemp(1)
            , lemp(2)
            , lemp(3)
         from emp
        where empno = 7369;
    
       for i in 1..lemp.count
       loop
         dbms_output.put_line(to_char(lemp(i)));
      end loop;
    end;   
    
  • need help to get the value using the REGEXP_REPLACE function.

    I am trying to extract the value placed between "< listitems >... < / listitems >" but I am unable to get these value using the REGEXP_REPLACE function.
    select REGEXP_REPLACE('<InputParameters></ParamSet><listitems>14545454</listitems></ParamSet></InputParameters>'
    ,'(<InputParameters>.*<listitems>)(.*)(</listitems>.*<InputParameters>)'
    ,'\2') from dual;
    required output:
     1454554
    Can someone please help me achieve this goal.

    Hello

    You forgot the / before the last InputParameters. If fix you that, your code will work.

    Here is a slightly different way:

    SELECT  REGEXP_REPLACE ( '14545454'
                     , '^.*?(.*?).*$'
                     , '\1'
                     )     AS listitems
    FROM    dual
    ;
    

    Least to type, the less likely you will have to make typos.
    If there are 2 (or more) elements of listitmes, 1 will be returned.

    From Oracle 11.1, you can also use REGEXP_SUBSTR. I have Oracle 10.2 avaialable now, so I can test the following, but I think you'd say:

    SELECT  REGEXP_SUBSTR ( '14545454'
                     , '(.*?)'
                     , 1
                     , 1
                     , NULL
                     , 1
                     )     AS listitems
    FROM    dual;
    

    When it comes with the text that is or looks to, XML, consider using XML functions.

Maybe you are looking for