Select Statement to query smallest ID

<My_Table>
ID
PHOENIX005
PHOENIX006
PHOENIX007
PHOENIX008
TUCSON001
TUCSON002
TUCSON003
TEMPE010
TEMPE011
TEMPE002
CHANDLER030
CHANDLER031
CHANDLER032
Whats the best way to write a select statement that would only bring back the IDs with the smallest numerical value? I ultimately want my Query to display:
ID
PHOENIX005
TUCSON001
TEMPE010
CHANDLER030

Or may be like this...
SQL> ed
Wrote file afiedt.buf
  1  with t as (
  2             select 'PHOENIX005' id from dual union all
  3             select 'PHOENIX006' from dual union all
  4             select 'PHOENIX007' from dual union all
  5             select 'PHOENIX008' from dual union all
  6             select 'TUCSON001' from dual union all
  7             select 'TUCSON002' from dual union all
  8             select 'TUCSON003' from dual union all
  9             select 'TEMPE010' from dual union all
10             select 'TEMPE011' from dual union all
11             select 'TEMPE002' from dual union all
12             select 'CHANDLER030' from dual union all
13             select 'CHANDLER031' from dual union all
14             select 'CHANDLER032' from dual
15            )
16  select *
17  from
18  (
19     select id, row_number()over(partition by trim(translate(id,'0123456789', rpad(' ',10))) order by
20     to_number(trim(translate(id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', rpad(' ',26)))) ) as rno
21     from t
22* ) where rno=1
SQL> /
ID                 RNO
CHANDLER030          1
PHOENIX005           1
TEMPE002             1
TUCSON001            1
SQL>

Similar Messages

  • Need help with select statement or query

    Not familiar with what to call it, but here is what i need...
    To give our analyst a better idea of warranty on some of our
    equipment, i
    would like to add to the page a column that displays if the
    device is still
    under warranty
    I currently capture the date the equipment was returned from
    repair, so what
    could i use within my select statement or query to display a
    warranty
    expiration date or display on the page...
    example :
    Returned from repair 10/20/2006 warranty expires on
    11/20/2006
    each equipment has different warranties, so i need a formula
    or something to
    say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
    =
    12/19/2006 )
    I would imagine this to be a query
    Table 1 would contain the equipment type and warranty time
    Table 2 would contain the current status of the equipment
    Query would take the back from repair date + warranty =
    expiration date

    Simple. Join the two tables and create a derived column for
    the expiration date. The exact syntax is dependant on your DBMS, so
    check the manual for whichever you are using and look at the date
    functions. There will be a function that will allow you to add a
    number of date units (day, month, year, etc) to a date
    field.

  • Using plsql tables in select statement of report query

    Hi
    Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
    thanks in advance
    suresh

    hi,
    u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
    declare
    ur_file utl_file.file_type;
    my_result varchar2(250);
    begin
    ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
    utl_file.get_line(ur_file, my_result);
    dbms_output.put_line(my_result);
    utl_file.fclose(ur_file);
    end;
    make sure u have an entry in ur init.ora saying that your
    utl_file_dir = '\your directory where ur files reside'
    cheers!
    [email protected]

  • Slow query results for simple select statement on Exadata

    I have a table with 30+ million rows in it which I'm trying to develop a cube around. When the cube processes (sql analysis), it queries back 10k rows every 6 seconds or so. I ran the same query SQL Analysis runs to grab the data in toad and exported results, and the timing is the same, 10k every 6 seconds or so. r
    I ran an execution plan it returns just this:
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 136,019  Bytes: 4,954,594,096  Cardinality: 33,935,576       
         1 TABLE ACCESS STORAGE FULL TABLE DMSN.DS3R_FH_1XRTT_FA_LVL_KPI Cost: 136,019  Bytes: 4,954,594,096  Cardinality: 33,935,576  I'm not sure if there is a setting in oracle (new to the oracle environment) which can limit performance by connection or user, but if there is, what should I look for and how can I check it.
    The Oracle version I'm using is 11.2.0.3.0 and the server is quite large as well (exadata platform). I'm curious because I've seen SQL Server return 100k rows ever 10 seconds before, I would assume an exadata system should return rows a lot quicker. How can I check where the bottle neck is?
    Edited by: k1ng87 on Apr 24, 2013 7:58 AM

    k1ng87 wrote:
    I've notice the same querying speed using Toad (export to CSV)That's not really a good way to test performance. Doing that through Toad, you are getting the database to read the data from it's disks (you don't have a choice in that) shifting bulk amounts of data over your network (that could be a considerable bottleneck) and then letting Toad format the data into CSV format (process the data adding a little bottleneck) and then write the data to another hard disk (more disk I/O = more bottleneck).
    I don't know exedata but I imagine it doesn't quite incorporate all those bottlenecks.
    and during cube processing via SQL Analysis. How can I check to see if its my network speed thats effecting it?Speak to your technical/networking team, who should be able to trace network activity/packets and see what's happening in that respect.
    Is that even possible as our system resides off site, so the traffic is going through multiple networks.Ouch... yes, that could certainly be responsible.
    I don't think its the network though because when I run both at the same time, they both are still querying at about 10k rows every 6 seconds.I don't think your performance measuring is accurate. What happens if you actually do the cube in exedata rather than using Toad or SQL Analysis (which I assume is on your client machine?)

  • How to edit the records value fetched by select statement query in sqldever

    How to edit the records value fetched by select statement query in sqldever 2.1.1.
    EX-
    SELECT * FROM emp WHERE ename like 'Jaga%'
    Edited by: user9372056 on Aug 31, 2010 2:16 AM

    Hi,
    Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
    SQL Developer
    Maybe your chances are better there.
    Regards
    Peter

  • Query on Select Statement

    Dear All,
            I have a small query on the Select Statement. If there are 2 identical rows and if i am retrieving them using the Select Statement, then will the select statement retrieves both the rows which are identical or only the first possible occurence? Pls help me out in this.
    Thanks,
    Sirisha.

    Hi,
         That depends on the statement u use. If u use, 'SELECT' statment, u can retrieve all the records which are identical with one or few fields. For that, u need to put the output INTO A TABLE.
    Ex. 1
    data : int_ekko type table of ekko with header line,
             fs_ekko type ekko.
    select * from ekko into table int_ekko where ebeln = '6361003191'.
    Here, int_ekko is an internal table contains all records whose EBELN = 63610003191.
    2)  If u use 'SELECT  SINGLE', then it will retrieve only the first record out of all the records who satisfy the condition EBELN = 6361003191.
    Ex 2:
    select single * from ekko into fs where ebeln = '63610003191'.
    'fs' is not a table, just of type structure. so contains only one record.
    Hope it help u..
    Kindly reward points if hepful
    Regards,
    Shanthi.
    Edited by: Shanthi on Mar 4, 2008 8:17 AM

  • Query in SELECT statement!!!!

    Hi all,
              I have a SELECT statement as follows:
      SELECT aguid_hi bpartner_no
      FROM crmd_link AS a
      INNER JOIN crmd_partner AS b ON bguid EQ aguid_set
      INTO TABLE p_partners
      FOR ALL ENTRIES IN i_sub_contracts
      WHERE a~guid_hi     EQ i_sub_contracts-guid
        AND a~objtype_hi  EQ '05'
        AND b~partner_fct EQ p_partner_fct.
    Please tell me if I can create a view for the above.
    Once I create a view for the above will it really boost the performance.
    Kindly reply immediately as this is bit urgent.
    Regards,
    Vijay

    hi,
    As said above view is nothing but an inner join between tables which you are already doing it in your program ... So i don't think there will be any improvement in the performance of the program ...
    Regards,
    Santosh

  • Query regarding Oracle SQL select statement

    Hi,
    How does Oracle ensures a consistent snapshot with the select statement
    without locking the table. My question is summarized with an example below:
    1. At time T1, Oracle select statement is fired and is fetching the result.
    2. At time T2, some DML operation is performed on the same table on which
    the select was executed and a commit was fired.
    3. At time T3, The Oracle select statement (Step 1) completes.
    My question is whether the records of transaction at time T2 will be visible at time T3 or not?
    If "not", then does it mean that Oracle retrieves the rows from the time of last commit.
    I would also like to know if for the above mechanism, Oracle would make use of the rollback segemt to access the rows at a particular instant of time.
    TIA
    Regards,
    Raj

    This is called Read Consistency in the oracle. Its all about SCN before starting the transaction.
    Lets say
    1. T1 executs SELECT statement on EMP table.
    2. T2 made an update on the EMP and commited.
    But, T1 only still sees only old image of the data not the new one. This is called read consistency.
    You will be having two images in the buffer, one is consistent and changed image.
    When the T1 give SELECT statement it notes the SCN of the transaction. Read oracle document about read consistency.
    SJH.

  • Querying many tables at once from a select statement for specific values

    Hi all,
    I'm very new to PL/SQL and have a daunting task ahead of me. I'm pretty sure our database normalization scheme is all out of whack, which I dont have the experience to fix yet, but this is the task ahead of me without getting to change or fix our structure:
    in the universe has 1000+ tables.
    need--> Some of those tables have fields that contain a value that has to be changed.
    The only thing I have to go on is the column name will contain 'EMP'... but there is no specific naming convention for the column names.
    When I search on:
    select * from all_tab_columns where column_name like UPPER('%EMP%')
    It returns 750 rows. (So 750 rows = 750 columns in 500 different tables (some tables have 2 or more columns in it))
    tables names are random (table1, table2, etc).
    columns names are random with EMP in it (column1,column2,etc).
    I have 75 possible field values that I need to check each of those 750 columns for.
    Maybe this is too messy, but I'm looking at subqueries, joins, arrays, cursors, etc, anything to minimize the amount of work I have to do.
    I think this is too much to do a join with, but that seems to be what all the documentation is pointing me to.
    can you point me to a simple example of what i could
    write?
    the logic i see it would be
    run the select statement to grab the column names that meet EMP.
    one at a time, search each column in the corresponding table for the 75 values.
    return the results of rows for each column/table that meet one of the 75 unique values.
    I'll have to also update each of the 75 values to (used to be values 1, 2, 3 ... to new values X1, X2, X3, etc.)
    Any help at all would be very helpful,
    aspiring pl/sql programmer but having a rough time of it

    I think you're looking to do something like the following pseudocode:
    BEGIN
        FOR tblrec IN (SELECT table_name, column_name
                         FROM all_tab_columns
                        WHERE column_name LIKE '%EMP%')
        LOOP
            FOR rec IN (SELECT ROWID
                          FROM tblrec.table_name
                         WHERE REGEXP_LIKE(tblrec.column_name, '(expr1|expr2|...)')
            LOOP
                DBMS_OUTPUT.PUT_LINE(
                    'Found expression on ROWID ' || rec.rowid
                    || ' in column ' || tblrec.column_name
                    || ' on table ' || tblrec.table_name);
            END LOOP;
        END LOOP;
    END;

  • Hint in Update or Select Statement in an inline query ??

    Hi ,
    I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
    Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
    update emp
    set salary = salary + (select /*+ full(a) parallel(a,4)  */ salary from Salary
                             where   experience > 5  and empno = 55 )
    where empno = 85Thanks
    Rede

    You would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
    update emp
    set salary = salary + (select /*+ full(a) parallel(a,4)  */ salary from Salary a
                             where   experience > 5  and empno = 55 )
    where empno = 85
    NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
    To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
    merge into emp e
    using (select /*+ full(s) parallel(s,4)  */ s.salary from salary s where s.experience > 5) s
    on (e.empno = s.empno)
    when matched then update
    set salary = s.salary;

  • Select Statement Query

    Hi,
    I need to perform the following selection:
    a. Based on Position Number -> select associate Pernr from PA0001
    b. based on this Pernr find value of STAT2 in PA0000.
    Is there an efficient way of carrying out this selection other than using 2 Select Statements?
    Note Pernr field is a primary key in both tables.

    How about using join statement:
    Since PERNR is a key field in both tables;
    SELECT P0~STAT2
    INTO TABLE <itab>
    FROM PA0001 AS P1 INNER JOIN PA0000 AS P0
        ON P1PERNR = P0PERNR
    WHERE <position number condition>
    Regards,
    A.Singh

  • Query for select statement

    Dear all
    is there any option in select statement to automatically generate serial number respect of data.
    for eg.
    1 101100110  shetal trade
    2 1110001178 CHEMICAL SOAP WORKS
    3..
    4..
    i don't  want to use loop (sy-tabix) ..
    thanks,
    Abhi

    Hi ,
    i don't want to use loop (sy-tabix) ..
    any particular reason for this ?
    as u cannot automatically generate serial number, u have to go for loop....endloop.
    Thanks
    Karthik

  • Select statement operators in ecc 6.

    Hi Experts,
    I have a small doubt about the '>=' ( greater than or equal to ) operator usage in select statement. Is this operator by any chance perform not as desired in ECC 6.0. Is it a good option to use 'GE' instead of '>='. ?
    It may sound a bit awkward, but still I would like to know. I am facing a situation, which could be related to this. An early response would be highly appreciated.
    I would request,you NOT TO REPLY with links/explanations which says how to use select statement. Only answer if you have the  answers related to this query.
    Regards,
    Sandipan

    >
    Jaideep Sharma wrote:
    > Hi,
    > The only difference is GE will take a little more time than >= as system need to convert the keyword into actual operator when fetching data from Database.
    >
    > KR Jaideep,
    ????? Every Open SQL statements is translated to the SQL slang the underlying database is talking regardless if you type GE or >=
    If the result differs using >= or GE i would open a call at SAP instead of asking in SDN.

  • Use of LIKE in where clause of select statement for multiple records

    Hi Experts,
    I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
    For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
    And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
    data : begin of t_dda occurs 0,
            dda(19) type c,
           end of t_dda.
    data : begin of t_bukrs occurs 0,
            bukrs type t012k-bukrs,
           end of t_bukrs.
    data : dda type t012k-bankn,
           w_dda type t012k-bankn.
    CONCATENATE '%'
                             '2ARS1'
                     INTO  W_DDA.
    MOVE W_DDA TO T_DDA-DDA.
    APPEND T_DDA.
    CLEAR T_DDA.
    free t_bukrs.
    SELECT BUKRS
      FROM T012K
      into TABLE t_bukrs
        for all entries in t_dda
    WHERE BANKN like t_dda-dda.
    Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
    Thanks in advance,
    Akash

    Hi,
    yes, For All entries won't work for LIKE with '%  '.
    I think the other alternative is go for Native SQL by writing sub-query
    sample code is here:
    data: begin of i_mara occurs 0,
              matnr like mara-matnr,
              matkl like mara-matkl,
           end of i_mara.
    exec sql.
    select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
    endexec.
    loop at i_mara.
    write:/ i_mara-matnr, i_mara-matkl.
    endloop.
    hope u got it.
    regards
    Mahesh
    Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM

  • BI Publisher : SELECT statement in RTF template

    Hi Guys
    I have written a BI Publisher Report using XML file created from Oracle Reports(in Oracle Apps).
    Repors runs from Oracle Apps perfectly ok. Now I need to fetch some data from couple of tables and display on the Report.
    I am wondering whether I can directly code SELECT statement in RTF file rather than messing with Oracle Report(.rdf) file.
    Please advise.
    Thanks and Regards
    Vijay

    Hey Vijay,
    You cannot query in RTF using select :)..
    You have to mess/play with RDF to do it ;)
    Oh wait, did i say , we cannot in RTF, we can , but that is difficult approach to go with., keep this as an end of the world option.

Maybe you are looking for

  • JTextPane and RTF line returns

    I'm wondering is there anyway to use a line return with JTextPane's? I'm not sure if thats what they're called but what i'm talking about is the RTF equivelent of <BR>. I tried importing a file with line returns and none of they were treated as a spa

  • Removing unused IDOC fields

    Hi All , Removing unused IDOC fields using an XSLT editor is possible? If so, we can import them the IDOC as XSD correct? What will be the immediate benefit of such a tweak? Thanks XA

  • Why does internet explorer stop working when I open up a tutorial in Photoshop Elements 12?

    Why does my internet explorer stop working when I upen up a tutorial for Photoshop Elements 12?

  • Regd Footer in Webui

    Dear all, I am using SAP Integrated ITS 640 patch level 18 . I want to know whether we can change the footer display  in webgui . In SAP GUI for window we can change the footer in such a way to display the transaction / program / system / client etc

  • Printing without dialog box

    I would like to print from the .swf without seeing a regular OS print dialog box. Is there anyway around this? I am currently using the print command with bframe.