Order of records in o/p  of select statement

Hi all
I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
circumstances the order of the records of the select statement is different.
sample select statement which I need to execute
select emp_no from emplyees where designation = 'programer'
in one word order of records of in the o/p of a select statement will be unique ?
(provided same query same, table,)
can u plz quote the link to get more information
regards
Renjith

Hi,
YES, you can
Do Order By Without Using Order By Clause
in your select statement.
I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
Solution 1:
Select Emp_no
from Emp
group by Emp_no;
the o/p will be in the sorted in the Ascending order.
Solution 2: ( Only for columns holding Numeric Values )
Select Emp_No
From Emp
Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
Note: You Should only use this method on not very large tables coz of performance issue.
Hope this will solve your problem.
Any Comment on this, any body.
Thanks and Regards
There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem.

Similar Messages

  • Collumn order changes when i retrive data through select statement.

    Hi
    i am using the sql developer 2.1.1.64 i have below table with respected collum sequence.
    tbl_message( id,
    date,
    process_name,
    stage,
    message,
    message_type,
    parameter)
    when i retrive this table using select * from tbl_message; i got the below collumn sequence
    date process_name stage id message message_type parameter
    13-may-2011 procedure 10 1 info info null
    but when i create the table my id collumn is the first collumn?
    and when open the table through sql developer id collumn is in the first place. so why id collumn is in 3rd place when i use select statement?
    if you need more information lpease let me know.
    Thanks
    Ritesh

    SQL Developer allows you to change the order of the columns in the Output window, and it will remember it. This is probably why you see the columns in a different order when you execute "SELECT * FROM ..."
    The actual order of the columns in the database is what you see when you execute the DESC command.
    You also can verify the order of the columns in two other ways:
    1) Use SQL*PLus and exeute your "SELECT * " query. SQL*Plus will not re-arrange the columns.
    2) Query the data dictionary. Use user_tab_columns (if you are the owner of the table), or use all_tab_columns and add the schema owner to the query otherwise.
    SELECT table_name, column_name, column_id
    FROM user_tab_columns
    WHERE table_name  = 'TBL_MESSAGE';

  • Insert order by records into a view with a instead of trigger

    Hi all,
    I have this DML query:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dtable_view is a view with an INSTEAD OF trigger and table_name is a table with my records to be inserted.
    I need the ORDER BY clause because in my trigger i call a procedure who treat each record and insert into a table, used in the view. I need to garantee these order.
    If i put an other SELECT statement outside, like this:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dIt works. But I can put these new SELECT because these query is created automatic by Oracle Data Integrator.
    What I'm asking you is if there any solution to this problem without changing anything in the Oracle Data Integrator. Or, in other words, if there is any simple solution other than to add a new SELECT statement.
    Thanks in advance,
    Regards.

    Sorry... copy+paste error :)
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
        SELECT   *
          FROM   (  SELECT   a,
                             b,
                             c,
                             d,
                             e
                      FROM   table_name
                  ORDER BY   d)I need to insert him by a D column order, because my trigger needs to validate each record and insert him. I have some restrictions. For example, my records are:
    2     1     2006     M
    1     2     2007 M
    1     3     2007     S 2007
    1     2     2007     S 2007
    2     1     2009     S
    2     1     2009     S
    I want to insert the 'M' records first and then the 'S' records because the 'S' records only makes sense in target table is exists 'M' records
    Regards,
    Filipe Almeida

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • How to use SELECT statement  to extract KNA1-NAME1 and KNB1-ZSABE

    In building table I_KNA1 in  form f_extract_data, an additional select statement is needed to select and  append datafrom (KNA1 and KNB1) to existing I_KNA1
    In form f_extract_data table i_kna1 is populated with data from zd_kna101.(where ZD_KNA101 is a view of KNA1, KNB1 and KNBK.  It's a joint of these three tables.)  This will take care of all customers with KNBK-BANKL and KNBK-BANLN populated.  But this does not include new customers created in SAP CRM (no KNBK records).  Therefore a separate SELECT statement is needed to extract KNA1-NAME1 and KNB1-ZSABE for customers created in SAP CRM(the customers who do do not have BANKL and BANKN). These selected records are then need to be appended to I_KNA1.  It's possible that new selection statement might extract records that are already in existing I_KNA1 table.  IF this is the case, right after the append, sort I_KNA1 and remove duplicate records.
    form f_extract_data.
    select kunnr                         " Customer Number
             name1                         " Name
             zsabe                         " Business Unit
             bankl                         " Legacy Bank Key
             bankn                         " Legacy Bank Account
        from zd_kna101                     " View of KNA1, KNB1, and KNBK
        into table i_kna1
        for all entries in i_doc_by_ref
       where kunnr = i_doc_by_ref-kunnr
        and zsabe in s_zsabe.           
      if sy-subrc <> 0.
        message a116 with 'customer'.  " Customer Table is empty.  HALT!!!
      else.                                                    
        sort i_kna1 by kunnr.                                  
      endif.
    will I have to use the join statement(for KNA1-NAME1 and KNB1-ZSABE using the key as KUNNR) here or give two seperate select statements for extracting data from KNA1 and KNB1 using the key as KUNNR.
    THANKS FOR THE HELP.

    I would suggest using the join on KUNNR.  Maybe something like this.
    data: begin of itab occurs 0,
          kunnr type kna1-kunnr,
          name1 type kna1-name1,
          ZSABE type knb1-ZSABE,
          end of itab.
        select kna1~kunnr kna1~name1 knb1~zsabe
               into table itab
                    from kna1
                       inner join knb1
                            on kna1~kunnr = knb1~kunnr
                                   where ........
    Regards,
    Rich Heilman

  • Can i get an exact part of data from select statement

    hi...good afternoon...
    i want to fetch the records from a table by select statement. but i dont want to fetch the as it is record. i want to fetch a particular part of eacg record in that column.
    for example..
    table_name=tab1
    column_name=col1
    the col1 contains datas like *'customer search-cs', 'get customer-gc', 'customer delete-cd'* etc etc..
    now while writing the select query, i want to get the descriptive output as get customer, customer search, customer delete....that is i dont want the symbols..
    is it possible to get this???
    plss suggest...

    You mean like these possible ways of doing it...
    SQL> ed
    Wrote file afiedt.buf
      1* select substr('customer search-cs',1,length('customer search-cs')-3) from dual
    SQL> /
    SUBSTR('CUSTOME
    customer search
    SQL> ed
    Wrote file afiedt.buf
      1* select regexp_substr('customer search-cs','^[^-]*') from dual
    SQL> /
    REGEXP_SUBSTR('
    customer search
    SQL>

  • I upgraded to yosemite and iOS 8 in order to record with quicktime. But when I select Record a new movies I immediately get an Operation Could not be completed error.

    I upgraded to yosemite and iOS 8 in order to record with quicktime. But when I select Record a new movies I immediately get an Operation Could not be completed error. When I choose record audio or screenshots, I get a little further, but as soon as I select my ipad as the source I get the same error message.

    You don't need to be a developer for this to work. I get the same error. Just one more thing on the list that make me upset more and more with Apple. Things just don't work out of the box like they used to.
    This new feature was to be included with iOS 8 and Yosemite.

  • Ordering the records prior to select

    I have a table 'orderlines' with columns line_id, ship_flag, service_flag, bom_order.
    I need to generate the order line number in the following way
    select the orderlines order by bom_order
    for the first line the line number is 1.0
    for the next line if ship_flag is 'Y' then line_number is 1.1 else the line number is 2.0
    for the next line if the previous line ship_flag was ' Y' and service_flag is 'Y' then line number is 1.1.1 else
    if ship_flag is 'Y' then line number is 1.2, else 3.0
    so we have a package UTIL and function get_number where there is a global variable to capture the previous numbers (line number, ship number and service number) and based on the flag increment appropriate number and generate the line number as varchar2.
    I create a view
    create or replace view order_with_lineno is
    select line_id,
    util.get_number(ship_flag, service_flag) as line_number,
    from orderlines order by bom_order;
    This view doesnot give me the correct line_number, becaue the sorting happen after the line_number generation is done.
    can someone give me a solution for this?

    This is making some assumptions about how your flags are set, but if the data looks like the following, you can use a query for this:
    create table orderlines
    bom_order number,
    line_id number,
    ship_flag varchar2(1),
    service_flag varchar2(1)
    delete from orderlines;
    insert into orderlines values (1000,10,'N','N');
    insert into orderlines values (1000,20,'Y','N');
    insert into orderlines values (1000,30,'N','Y');
    insert into orderlines values (1000,40,'N','Y');
    insert into orderlines values (1000,50,'Y','N');
    insert into orderlines values (1000,60,'N','Y');
    insert into orderlines values (1000,70,'N','Y');
    insert into orderlines values (1000,80,'N','Y');
    insert into orderlines values (2000,10,'N','N');
    insert into orderlines values (2000,20,'Y','N');
    commit;
    SELECT bom_order,
           line_id,
           l1||'.'||l2||decode(l3,0,'','.'||l3) new_line_id
    FROM   (
            SELECT bom_order,
                   line_id,
                   l1,
                   l2,
                   sum(decode(service_flag,'Y',1,0)) OVER (PARTITION BY bom_order,l2 ORDER BY line_id  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) l3
            FROM
                    SELECT bom_order,
                           line_id,
                           service_flag,
                           dense_rank() OVER (ORDER BY bom_order) l1,
                           sum(decode(ship_flag,'Y',1,0)) OVER (PARTITION BY bom_order ORDER BY line_id  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) l2
                    FROM   orderlines
    BOM_ORDER    LINE_ID NEW_LINE_ID
          1000         10 1.0
          1000         20 1.1
          1000         30 1.1.1
          1000         40 1.1.2
          1000         50 1.2
          1000         60 1.2.1
          1000         70 1.2.2
          1000         80 1.2.3
          2000         10 2.0
          2000         20 2.1Greg Pike
    http://www.singlequery.com
    Message was edited by:
    gfpike
    Had a raw data error.

  • Retrieve the Purchase Order Condition Records Table

    Hallo!
    I have found this code right here:
    http://www.sap-basis-abap.com/sapab025.htm
    It is very useful particular for purposes which I need. Please can somebody
    try to fix the error to get it working. There is an internal table missing.
    Regards
    Ilhan
    Retrieve the Purchase Order Condition Records Table
    select * from ekko.
           select * from konv where knumv = ekko-knumv
               "Get all the condition records for the purchase order
           endselect.
    endselect.
    * Get the info record conditions record
    * First declare the record structure for the key
    data: begin of int_konp,
                 txt1(5),
                 lifnr(5),
                 matnr(18),
                 txt2(4),
                 txt3(1),
            end of int_konp.
    clear: konh, konp, int_konp.
    * data for the record key konh-vakey
    int_konp-txt1    = '00000'.
    int_konp-lifnr    = ekko-lifnr+5(5).
    int_konp-matnr = ekpo-matnr(18).
    int_konp-txt2    = 'ALL'.
    int_konp-werks = ekpo-werks.
    int_konp-txt3    = '0'.
    select * from konh where      kschl = 'PB00'            "Conditions (Header)
                                         and datab => p_datum.       "valid from date
          if konh-vakey = int_konp.                                  "Conditions (Item)
                 select single * from konp where knumh = konh-knumh.
                 continue.
          endif.
    endselect.

    Hi flora
    Just get through the sequence .
    see the table fields ...
    1. From EKKO table take an entry which is having pricing conditions.
    Now in the fields list check out for field EKKO-KNUMV(document condition number).
    2.Take this condition number and now goto table KONV.
    Give the document condition number in the field  KONV-KNUMV and execute .
    This will lead to a list of document condition numbers and some other fields .
    3.Now check for field KONV-KNUMH ,KONV-KAWRT(quantity) and note the value KONV-KWERT  .
    (Remember this is at header level).
    This is ur condition record number.
    **comments
    Now from document condition number we got the condition record number (KNUMH).
    4. now since u want the item level tax procedure go to table KONP and give the condition record number and execute .
    This will give u a list of details .
    Now concentrate on KONV-KAWRT (scale quantity) KONP-KBETR(rate) as this table will store “Pricing  per UNIT “ so product of these two will give u the total pricing tax, for a particular condition type say PR00  .
    For that particular condition item .
    Check the pricing procedure .
    See t-code VK13 and check the pricing procedure .
    From me23 check the same PO num select the item and check the pricing conditions applicable .
    Select a particular pricing and goto condition->analysis->analysis pricing  ,
    Better take help of a SD functional consultant in the process.
    regards,
    vijay.

  • Regarding Purchase order info records

    Hi,
    How do I read the text maintained against purchase order info records, transaction ME12. What is the key that I should use for reading the text maintained.
    Regards,
    Vijay

    it may differ from system to system, so i will tell you how i determined this, rather than what i determined.
    In your development or test system, make a change to the text.
    now, use SE16 and look at table STXH. Put todays date in the TDLDATE selection (and your id for TDLUSER, if you want)
    You should see the changes you made, and the keys associated with the texts. you can then use the FM READ_TEXT to get the text...
    Hope this helps

  • ORDER BY not allowed in INSERT..SELECT ?

    I'm trying to INSERT..SELECT into a table, the SELECT should be ordered by a clause, but Oracle (8.1.7) does not permit that.
    INSERT INTO SumTable
    SELECT Field1,Field2
    FROM FullTable
    WHERE field1 = 1
    ORDER BY field2;
    I get: ORA-00933: SQL command not properly ended
    It doesn't matter if the "order by" field is part of the SELECT or not. When I remove the ORDER BY the INSERT works perfectly. Oracle docs do not mention this limitation. Is this known issue? Can I make it to work?
    I do have a solution in PL/SQL, open a cursor for the SELECT with the ORDER BY, INSERT one row at a time in the cursor loop, but its too slow when I have more than 10K records to insert.
    Thanks,
    Yoram Ayalon

    I have to take issue with this. rows are inserted based on the blocks on the freelist.
    Watch.
    We will create a feeder table.
    SQL> create table feeder (ID) pctfree 0 as select rownum from all_objects;
    Table created.
    SQL> create table FRED (mycol integer) pctfree 0 pctused 99;
    {99 so that free space is reused almost immediately for demo only }
    Table created.
    SQL> analyze table fred compute statistics;
    Table analyzed.
    SQL> select blocks from user_tables where table_name='FRED';
    BLOCKS
    0
    SQL> insert into fred (mycol) select id from feeder where id <=32000;
    32000 rows created.
    { So we now have a tightly packed table. Blocksize 8k by- the-by )
    SQL> analyze table fred compute statistics;
    SQL> select blocks from user_Segments where segment_name='FRED';
    BLOCKS
    48
    { Ok : 48 blocks.  Now we will get rid of 1/2 of the rows scattered throughout the 48 }
    SQL> delete from fred where mod(mycol,2) =0;
    16000 rows deleted.
    SQL> analyze table fred compute statistics;
    Table analyzed.
    SQL> select blocks from user_Segments where segment_name='FRED';
    BLOCKS
    48
    { Ok : Still 48 blocks since we haven't been inserting only deleting }
    [ if we looked at user_Tables now it would show most if not all of the blocks on the freelist given the 99 PCTUSED }
    { now let's chuck in another 16000 ordered rows }
    SQL> insert into fred (mycol) select id from feeder where id <=16000 order by id
    16000 rows created.
    SQL> analyze table fred compute statistics;
    Table analyzed.
    SQL> select blocks from user_Segments where segment_name='FRED';
    BLOCKS
    48
    { look ! no extra blocks ! 
    -> it must have filled the non-contiguous holes in the blocks
    -> the rows are not physically ordered.

  • SELECT statement INTO TABLE - what determines order of entries in in.table?

    Hello everyone.
    I habe a question: A select statement selects multiple entries from a data base table that are put into an internal table.
    The question : What determines the order of the entries in the internal table? 
    And what might change the order all of a suddden in that internal table?
    Could reorg. activities/archiving (even ongoing) cause any different result in the order as before ?
    I do not mean different entries but I rather refer to the sorting of the internal table, if it is not explicitly stated in the select or in parts of the coding.
    Any explaination is appreciated!
    Thanks!
    CN.

    Hi,
    Its not the order in which you specify the fields in the where clause that affects the sequence of the selection.
    What I said is that by default the entries are sorted by the primary key of the table.
    I did a bit of a test out of curiosity and after seeing so many different replies on the thread. I was surprised to see the results of the different scenarios.
    REPORT  Z_TEST_SELECTION                        .
    tables vbap.
    data it_vbap type table of vbap.
    data it_vbak type table of vbak.
    select-options s_vbeln for vbap-vbeln.
    select-options s_posnr for vbap-posnr.
    "======================================================================
    "s_vbeln has following entries
    " 5
    " 6
    " 1
    " 2
    "s_posnr has following entries.
    " 10
    " Sorts in ascending order by VBELN and POSNR by default
    select * up to 20 rows from vbap into table it_vbap.
    refresh it_vbap.
    "Below two cases are absolutely unreliable and I would suggest that a
    "sort should be mentioned after these statements. So when we use select
    "options specify values with the in clause, the sort is not reliable.
    "Strangely , neither the sequence is not determined by the order in
    "which the data was entered in the select option nor in the sequence of
    "the primary key. And this is still a mystery to me about the order in which
    "the entries are selected.
    " Any answeres anyone ?
    "1.
    select * from vbap into table it_vbap
    where  vbeln in ('0000000002','0000000006','0000000005','0000000001')
    and posnr in s_posnr.
    * Resulted in
    *900  |0000000001|000010|
    *900  |0000000005|000010|
    *900  |0000000006|000010|
    *900  |0000000002|000010|
    "=========================================================
    "2.
    select * from vbap into table it_vbap
    where  posnr in s_posnr
    and    vbeln in s_vbeln.
    * Resulted in
    *900  |0000000002|000010|
    *900  |0000000001|000010|
    *900  |0000000005|000010|
    *900  |0000000006|000010|
    refresh it_vbap.
    "Here the orders were selected in Decending order of Sales order, however
    "the posnr is not mentioned in the order by clause, hence posnr was
    "still in ascending order.
    select * from vbap into table it_vbap
    where posnr in s_posnr and vbeln in s_vbeln
    order by vbeln descending.
    write : 'done!'.
    refresh it_vbap.
    "Here the orders were selected in Descending order of Sales order.
    select * from vbak into table it_vbak where vbeln in s_vbeln
    order by vbeln descending.
    " The entries were selected in the ascending order of the key VBELN and
    " POSNR, so it seems that for all entries does not affect the selection of records.
    select * from vbap into table it_vbap
    for all entries in it_vbak
    where vbeln = it_vbak-vbeln
    and   posnr in s_posnr.
    Of course if you change the order of the primary key (in the transparent table, not in the where clause), the entries will be sorted as per the changed key.
    But we seldom change the the sequence of the primary key. In most cases we normally add a new field and make it a key field in addition to the existing key fields.
    I hope this helps you.
    There might be many more cases and examples than given above, which you can try and reply on this post. Lets see what we come up with.
    regards,
    Advait

  • Select statement takes very long to run with order by clause.

    Hi all,
    I have a select statement which when I run without the order by clause takes arround 2 minutes to run. But with the order by clause it goes on for ever. I am trying to access the database server through a network which is not too fast.
    The select statement is based on 9 views which are again based on some views. It also has inline views and outer joins. These views and inline views can not be done away with.
    When selected without the order by clause it gives 3215 records.
    Anything like 2 to 3 minutes will be Ok.
    Thanks.
    --Malay                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    The select statement is as follows :-
    SELECT f.system_name,
    a.signal_type,
    f.sys_signal_name,
    a.bus_desc,
    b.vl_ident,
    b.vl_name,
    b.src_mac,
    b.src_mac_addr,
    b.dest_mac,
    b.dest_mac_addr,
    b.network,
    bb.bufr_size_in_bytes,
    bb.bag_in_ms,
    bb.is_rma_used,
    bb.is_ic_used,
    bb.sub_vl_cnt,
    bb.skew_max_in_ns,
    cc.msg_name,
    c.src_ip,
    c.src_ip_addr,
    c.src_port,
    c.dest_ip,
    c.dest_ip_addr,
    c.dest_port,
    cc.rate_in_ms,
    cc.tx_mode,
    cc.protocol,
    cc.port_type,
    cc.msg_length_in_bytes,
    d.mnemonic,
    d.start_addr32,
    d.lsb,
    d.end_addr32,
    d.msb,
    d.format,
    d.init_value,
    d.fs_mnemonic,
    d.fs_afdx_data_id,
    d.digital_data_id,
    DECODE(
    d.digital_datatype,
    NULL, '',
    'UNUSED', '',
    api$util.concat_column_data(
    'api_'
    || d.digital_datatype,
    'digital_data_id',
    d.digital_data_id,
    bool.FALSE
    ) AS data_details,
    f.connection_id
    || '_'
    || a.digital_bus_id
    || '_'
    || b.afdx_vl_id
    || '_'
    || bb.afdx_output_id
    || '_'
    || c.afdx_frame_id
    || '_'
    || cc.afdx_msg_id
    || '_'
    || d.afdx_data_id AS KEY
    FROM api_afdx a,
    api_afdx_vl b,
    api_afdx_output bb,
    api_afdx_frame c,
    api_afdx_msg cc,
    api_afdx_data d,
    vf_signal e,
    (SELECT DISTINCT aa.signal_id,
    cc.system_name,
    bb.connection_id,
    bb.sys_signal_name
    FROM vf_nodes aa,
    vf_connections bb,
    vf_system cc
    WHERE aa.connection_id = bb.connection_id
    AND bb.system_id = cc.system_id) f
    WHERE e.signal_id = f.signal_id(+)
    AND e.digital_bus_id = a.digital_bus_id
                   AND a.digital_bus_id = bb.digital_bus_id(+)
    AND bb.afdx_output_id = b.afdx_output_id(+)
                   AND b.afdx_vl_id = c.afdx_vl_id(+)
    AND bb.afdx_output_id = cc.afdx_output_id(+)
    AND cc.afdx_msg_id = d.afdx_msg_id(+)
    ORDER BY f.system_name,
    a.signal_type,
    f.sys_signal_name,
    b.vl_name,
    cc.msg_name,
    d.start_addr32,
    d.lsb;
    Where api_afdx ,
    api_afdx_vl ,
    api_afdx_output ,
    api_afdx_frame ,
    api_afdx_msg ,
    api_afdx_data ,
    vf_signal ,
    vf_nodes ,
    vf_connections ,
    vf_system
    are all views.

  • If I want to order by dateAdded to I have to include it in the select statement like

    If I do this:
    <cfquery name="chart" datasource="#datasource#">
    select behaviourID,score, dateAdded2 = convert(varchar,
    dateAdded , 101)
    from staff_charts_data
    where userID =
    <cfqueryparam value="#arguments.userID#"
    cfsqltype="cf_sql_integer"> AND
    NOT score = 5
    </cfquery>
    If I want to order by dateAdded to I have to include it in
    the select statement like so:
    <cfquery name="chart" datasource="#datasource#">
    select behaviourID,score, dateAdded2 = convert(varchar,
    dateAdded , 101),dateAdded
    from staff_charts_data
    where userID =
    <cfqueryparam value="#arguments.userID#"
    cfsqltype="cf_sql_integer"> AND
    NOT score = 5
    </cfquery>

    you should be able to order by dateAdded without it being in
    the select clause. The only time the order by field has to be in
    the select clause is when your query has an aggregate and group by
    clause, like this:
    select field1, field2, max(field3) as youralias
    from sometables
    where whatever
    group by field1, field2
    order by ???
    You can only order field1, field2, max(field3) or youralias.
    You can't order by field4.

  • In Oracle SQL, cannot use column in select statement and order by

    Hi,
    Is there a work around for this.
    Thanks in advance
    Pablo.

    Hi,
    943981 wrote:
    Hi All,
    This is the error I get:
    ORA-00960: ambiguous column naming in select list
    00960. 00000 - "ambiguous column naming in select list"
    *Cause:    A column name in the order-by list matches more than one select
    list columns.
    *Action:   Remove duplicate column naming in select list.
    Error at Line: 6 Column: 17That error message looks pretty clear to me. What don't you understand?
    Either
    (a) use aliases, so each column has a unique name, or
    (b) remove duplicate columns from the SELECT clause.
    Post your query. It's hard to say exactly what you're doing wrong when we don't know exactly what you're doing.
    For best results, post a complete test script (including CREATE TABLE and INSERT statements, if necessary) that people can to re-create the problem and test their ideas.
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • Change status for 18 million messages in the Integration Engine

    Hello there! I have the following situation and I wonder that maybe you could help. Currently I have more than 18 million messages for the BC_XMB object in the Integration Engine for a BI System (connected to a PI system). The problem here is that th

  • Report painter insert line problem

    I have one report, many pages, 156 rows, now the requirement is insert five rows at row number 103, five rows including two character and three formula, but after i insert five rows, I need to adjust formula for those rows below the five rows, is the

  • Why do I have other people I cloud on a brand new iPad bought direct from Apple

    hi i bought my husband a new ipad direct from Apple and when we go to set it up it has 2 other peoples iCloud details on it. We don't know who they are and considering its brand new it doesn't make any sense. Has anyone else had this issue? if so how

  • My Apps arn't working on my Iphone

    Well, when my iphone opens an app, it will work for a bit, but will turn black and turn to the home screen -Texas Holdem -Dinner Dash -Cannan Challenge To name a few. I've tired the following that I've seen so far: - Delete apps from iphone and macbo

  • PDF printer missing from IE8 and Firefox 4

    I am using Acrobat Std V 9.4.5 and yesterday Acrobat notified me of an update.  I updated, and now I have no PDF printer in either of my browsers.  Should I reinstall Acrobat?