Retrive the second-highest value from the table using query.

Hi,
I am using Oracle 8i...
I have to retrieve the second-highest salary from the table...for this I need to write a SQL..Can anybody please help me to figure out this problem..Thanks in advance..
smitha

Using analytic functions
SELECT *
FROM (SELECT other_columns,DENSE_RANK() OVER(ORDER BY salary DESC) sal_rank
      FROM table)
WHERE sal_rank = 2
Using Order by and rownum
SELECT *
FROM (SELECT other_columns,rownum sal_rank
      FROM (SELECT other_columns,salary
            FROM table
            ORDER BY salary DESC))
WHERE sal_rank = 2TTFN
John

Similar Messages

  • Retrive a new sequence value from a table using Stored Procedure

    Dear experts
    i have written the following stored procedure, but i want this to return itemid to the environment. Please help as i am absolutely new to oracle.
    create or replace procedure "SP_ITEMS"
    (vitem IN VARCHAR2,
    vqty IN NUMBER,
    vrate IN NUMBER)
    is
    begin
    INSERT INTO ITEMS (item,qty,rate)
    VALUES (vitem,vqty,vrate);
    end;
    Thanks
    With regards
    Manish Sawjiani

    If you want a column to be automatically populated with a sequence, then you need to create a sequence, and create a trigger to populate the column with the sequence. You can use the returning clause in a select statement to return the value of the inserted sequence. You can do this with just sql or you can put it in a procedure. I have demonstrated both below. This is a general sql and pl/sql problem, not something specific to the Express Edition, so please post future such questions in the sql and pl/sql discussion group instead.
    SCOTT@10gXE> CREATE TABLE items
      2    (itemid NUMBER,
      3       item   VARCHAR2 (50),
      4       qty    NUMBER (10, 3),
      5       rate   NUMBER (10, 3))
      6  /
    Table created.
    SCOTT@10gXE> CREATE SEQUENCE item_sequence
      2  /
    Sequence created.
    SCOTT@10gXE> CREATE OR REPLACE TRIGGER items_bir
      2    BEFORE INSERT ON items
      3    FOR EACH ROW
      4  BEGIN
      5    SELECT item_sequence.NEXTVAL
      6    INTO   :NEW.itemid
      7    FROM   DUAL;
      8  END items_bir;
      9  /
    Trigger created.
    SCOTT@10gXE> SHOW ERRORS
    No errors.
    SCOTT@10gXE> VARIABLE g_itemid NUMBER
    SCOTT@10gXE> INSERT INTO items (item, qty, rate)
      2  VALUES ('item1', 2, 3)
      3  RETURNING itemid INTO :g_itemid
      4  /
    1 row created.
    SCOTT@10gXE> PRINT g_itemid
      G_ITEMID
             1
    SCOTT@10gXE> CREATE OR REPLACE PROCEDURE sp_items
      2    (p_item      IN  VARCHAR2,
      3       p_qty      IN  NUMBER,
      4       p_rate      IN  NUMBER,
      5       p_itemid OUT NUMBER)
      6  AS
      7  BEGIN
      8    INSERT INTO ITEMS (item, qty, rate)
      9    VALUES (p_item, p_qty, p_rate)
    10    RETURNING itemid INTO p_itemid;
    11  END sp_items;
    12  /
    Procedure created.
    SCOTT@10gXE> SHOW ERRORS
    No errors.
    SCOTT@10gXE> EXECUTE sp_items ('item2', 3, 4, :g_itemid)
    PL/SQL procedure successfully completed.
    SCOTT@10gXE> PRINT g_itemid
      G_ITEMID
             2
    SCOTT@10gXE> SELECT * FROM items
      2  /
        ITEMID ITEM                                                      QTY       RATE
             1 item1                                                       2          3
             2 item2                                                       3          4
    2 rows selected.
    SCOTT@10gXE>

  • How can we read the screen field values from the report selection screen wi

    Hi expart,
    How can we read the screen field values from the report selection screen with out having an ENTER button pressed  .
    Regards
    Razz

    use this code...
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_posnr.
    **Read the Values of the SCREEN FIELDs
    CALL FUNCTION 'DYNP_VALUES_READ'

  • New install of SQL 2014 Std MSDN. Get "The SQL Server product key is not valid. To proceed, re-enter the product key values from the Certificate of Authenticity (COA) or SQL Server packaging."

    Trying to install a new version of SQL 2014 Std 64 or x86. Installing on Windows 8.1Pro 64bit machine.
    I get:
    "TITLE: SQL Server Setup failure.
    SQL Server Setup has encountered the following error:
    The SQL Server product key is not valid. To proceed, re-enter the product key values from the Certificate of Authenticity (COA) or SQL Server packaging.
    Error code 0x858C0017."
    I looked at the summary log and that is the only error.
    I made sure there were no other instances of SQL on this machine. Uninstalled all VS2013 and sql instances just in case. IF there is somewhere to check if a previous version or license is causing the issue, i would be glad to check.
    Any help would be appreciated.

    Hi,
    Please read this thread with similar issue
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/bdd94577-515c-49fa-be44-008eacece057/installing-sql-server-2012-on-a-new-vm-error-code-0x858c0017?forum=sqlsetupandupgrade
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Articles

  • How to get second maximum salary from employee table(sql query)

    how to get second maximum salary from employee table(sql query)

    dude there is no matter of structure .........that user already said its from employee table ...............its basic table in sql and there is no need to specify the table structure
    .........i think u got my point I think you are the one who didn't understand Sarma's point.
    Give a man a fish and you feed him once. Teach a man how to fish and you feed him a life long.
    >
    and the query is
    select max(sal) from emp where sal<(select max(sal)
    from emp);
    this will give the 2nd max salary from the emp tableBtw: You solution is bad, because it needs to scan and sort the table emp twice. And a better solution has been given already.
    Message was edited by:
    Sven W. - reordered statements

  • How to get string value from database table using Visual Studio 2005?

    Hi,
    Im developing plugin in illustrator cs3 using visual studio 2005. I need to get the values eneterd in database. Im able to get the integer values. But while getting string values it is returning empty value.
    Im using the below code to get the values from database table
    bool Table::Get(char* FieldName,int& FieldValue)
        try
            _variant_t  vtValue;
            vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
            FieldValue=vtValue.intVal;
        CATCHERRGET
        sprintf(m_ErrStr,"Success");
        return 1;
    Im using the below code to get the values.
    AIErr getProjects()
        char buf[5000];
        int i;   
        std::string  catName;
        ::CoInitialize(NULL);
        Database db;
        Table tbl;
        errno_t err;
        err = fopen(&file,"c:\\DBResult.txt","w");
        fprintf(file, "Before Connection Established\n");
        //MessageBox(NULL,CnnStr,"Connection String",0);
        if(!db.Open(g->username,g->password,CnnStr))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        fprintf(file, "After Connection Established\n");
    if(!db.Execute("select ProjectID,ProjectName from projectsample",tbl))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        int ProjectID;
        int UserID;
        int ProjectTitle;
        char ProjectName[ProjectNameSize];
        if(!tbl.ISEOF())
            tbl.MoveFirst();
        ProjectArrCnt=0;
        for(i=0;i<128;i++)
            buf[i]='\0';
            int j=0;
        while(!tbl.ISEOF())
            if(tbl.Get("ProjectID",ProjectID))
                fprintf(file,"Project ID: %d ",ProjectID);
                ProjectInfo[ProjectArrCnt].ProjectID = ProjectID;
                sprintf(buf,"%d",ProjectID);
                //MessageBox(NULL, buf,"f ID", 0);
                j++;
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            //if(tbl.Get("ProjectTitle",ProjectName))
            if(tbl.Get("ProjectName",ProjectName))
                MessageBox(NULL,"Inside","",0);
                fprintf(file,"ProjectTitle: %s\n",ProjectName);
                //catName=CategoryName;
                ProjectInfo[ProjectArrCnt].ProjectName=ProjectName;
                //sprintf(buf,"%s",ProjectName);
                MessageBox(NULL,(LPCSTR)ProjectName,"",0);
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            ProjectArrCnt++;
            //MessageBox(NULL, "While", "WIN API Test",0);
            tbl.MoveNext();
        //MessageBox(NULL, ProjectInfo[i].ProjectName.c_str(),"f Name", 0);
        ::CoUninitialize();
        //sprintf(buf,"%s",file);
        //MessageBox(NULL,buf,"File",0);
        fprintf(file, "Connection closed\n");
        fclose(file);
        for(i=0;i<ProjectArrCnt;i++)
            sprintf(buf,"%i",ProjectInfo[i].ProjectID);
            //MessageBox(NULL,buf,"Proj ID",0);
            //MessageBox(NULL,ProjectInfo[i].ProjectName.c_str(),"Project Name",0);
        return 0;
    In the above code im geeting project D which is an integer value. But not able to get the project name.
    Please some one guide me.

    As I said in the other thread, this really isn't the place to ask questions about a database API unrelated to the Illustrator SDK. You're far more like to find people familliar with your problem on a forum that is dedicated to answering those kinds of questions instead.

  • Exchange Rate: Routine to copy  the "Exchange Rate" value From TCURR table

    Dear experts,
    I have created a cutomised Key Figure (ZEXCHRATE) with the 0currency as the unit and this field is included in my ZCOPA_C21 Infocube.
    In the update rule, it was then appointed with a simple routine below;
    (PROGRAM UPDATE_ROUTINE.
    $$ begin of global - insert your declaration only below this line  -
    TABLES: TCURR.
    DATA: IT_TCURT Type TCURR occurs 0 with header line.
    $$ end of global - insert your declaration only before this line   -
    FORM compute_data_field
      TABLES   MONITOR STRUCTURE RSMONITOR "user defined monitoring
      USING    COMM_STRUCTURE LIKE /BIC/CSZCOPA_TPL_IS
               RECORD_NO LIKE SY-TABIX
               RECORD_ALL LIKE SY-TABIX
               SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
      CHANGING RESULT LIKE /BIC/VZCOPA_C21T-/BIC/ZEXCHRATE
               RETURNCODE LIKE SY-SUBRC
               ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update
    $$ begin of routine - insert your code only below this line        -
    fill the internal table "MONITOR", to make monitor entries
      SELECT        * FROM  TCURR appending corresponding fields of table
      IT_TCURT
             WHERE  KURST  = 'M'
             AND    FCURR  = 'USD'
             AND    TCURR  = 'IDR'.
          AND    GDATU  = ___.
          AND    UKURS  = ___.
      Sort IT_TCURT by GDATU descending.
      Loop at IT_TCURT.
        Move IT_TCURT-UKURS to RESULT.
        Exit.
      Endloop.
    result value of the routine
    RESULT = space.
    if the returncode is not equal zero, the result will not be updated
      RETURNCODE = 0.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    $$ end of routine)
    Which will basically copy all the contents of TCURR into an internal table (IT_TCURT), sort it and then only copy out the UKURS (Exchange rate) data into the customised ZEXCHRATE to get the latest exchange rate value.
    Routine was checked and its fine.
    The problem is, upon checking the update rule, it returned an error message;
    "No Unit maintain for Key Figure Exchange Rate Local".
    Double checked the declaration of ZEXCHRATE, the unit was there.
    My questions;
    1. Is this the correct way of doing it ? I just want to be able to show the exchange rate value in my query (hence the existence of ZEXCHRATE).
    2. Is there an alternative way of achieving the same result ?
    Your help or advice will be greatly appreciated.
    Thanks
    KG

    Hi Sreeni,
    Referring to the " but the conversion from VEF to USD is happening at a rate @0.23256 which is valid till 02/13/2013 only" part in your post, the date given in OB08 for currency rate is valid from and not valid till.  Hence, please check the setting once.  Once you enter the rate from 02/13/2013, the rate is valid till you enter another date later than 02/13/2013.
    Regards,

  • WD4A with ALV, populating the header with values from the table

    I have WDA application that list schedule agreement headers in one ALV and when you select one the line items show in the second ALV2 below. We show quantity and net value  in 13 monthly buckets beginning with the validity data. The function returns the month text in columns I want to change the header based on the months returned. So instead of QNTY1, QNTY2 it would be 01/2008, 01/2008 etc. But ALV2 is initialized when the page is built and if I change the ALV2 settings after the line item function call they are not updated. On the page. Is there anyway I can do this???
    It tried put the code in the EXECUTE function method, and I tried WDMODIFYVIEW but the ALV is not refreshed.
    Thanks
    David

    Thanks for your help, I know I am probably doing something dumb but it is driving me crazy.
    I have debugged I can see the text change in the debugger but it doesn't show up on the screen. I removed the code from from the WDDOINIT. So am doing everything in the ONACTIONGETDETAIL to ensure that it is not being overwritten. I can change the 'number of lines', remove print button, change a field to an icon etc, but the column header doesn't change. If I put the same code in the WDDOINIT the column header does change. Everything else works in both places.
    *First ALV config
        l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
        IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
          l_ref_cmp_usage->create_component( ).
        ENDIF.
        DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
        lo_interfacecontroller = wd_this->wd_cpifc_alv( ).
        DATA lo_value TYPE REF TO cl_salv_wd_config_table.
        lo_value = lo_interfacecontroller->get_model( ).
    *activate extended functions of the alv.
        cl_salv_wd_model_table_util=>if_salv_wd_table_util_stdfuncs~set_all(
           r_model = lo_value ).
        lo_value->if_salv_wd_table_settings~set_visible_row_count( '10' ).
        lo_value->if_salv_wd_table_settings~set_selection_mode( '06' ).
        lo_value->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).
        DATA lr_column_settings TYPE REF TO if_salv_wd_column_settings.
        DATA lr_column TYPE REF TO cl_salv_wd_column.
        DATA lr_column_header TYPE REF TO cl_salv_wd_column_header.
        lr_column_settings ?= lo_value.
        lr_column = lr_column_settings->get_column( 'VBTYP' ).
        lr_column->delete_header( ).
        lr_column_header = lr_column->create_header( ).
        lr_column_header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).
        lr_column_header->set_text( '200708' ).
    *change column to icon
        lr_column = lo_value->if_salv_wd_column_settings~get_column( 'AUART_DESC' ).
        CREATE OBJECT lr_image.
        lr_image->set_source_fieldname( 'AUART_DESC' ).
        lr_column->set_cell_editor( lr_image ). "Display images in column
    Thanks again.
    David

  • How can I convert (or switch) the RGB percent values from the LR histogram into RGB values which are shown e. g. in PS/CameraRAW?

    In LR 5.5 (same in previous versions) the RGB values in the histogram are shown in percent (relativ) values. I prefere to see the absolute values, but I can`t find any way to switch. Maybe this option is intentional disabled, because LR works in 16-Bit mode this would result in values up to 2^16. But as i compared the relativ values from LR with the absolute values from PS i run into a conversion problem. The following example shows the differences:
    CameraRAW : RGB, 128,0,0
    Lightroom: RGB, 43,8%, 19,0%, 6,2%
    CameraRAW: RGB, 0,128,0
    Lightroom: RGB, 29,8%, 47,5%, 17,5%
    Mainly i have two questions:
    1. Is there any possibility to change the percent RGB values in LR to absolut values?
    2. How can i convert CameraRAW values to LR values (see above)?

    TThe reason that a design decision was made from the beginning of LR to show only the percentage values was that RGB values are dependent on the color space and the LR histogram and numerical readout are derived from the Develop module's display space which is a hybrid color space with ProPhoto RGB primaries and the sRGB TRC. Thus the numerical values in the display would be different from the exported RGB image (in an orthodox space) and it was feared that this would be misleading. When soft proofing was introduced, because it involved converting the display to an orthodox space, it became possible to use the 0-255 scale in that mode.

  • I am reading from an instrument a 1D string array of numbers in ascii. I want to be extract the actual data values from the string. How do I do that?

    labview 6i. Using sr785 instrument.

    Two ways. Use Fract/Exp to Number function on the Strin>Strin Number Conversion palette. It accepts both individual or strin array inputs. Wire your string array in an get an array of doubles out. You can also use Scan From String on the String palette inside of a for loop. The for loop will autoindex the string array in and autoindex an array of doubles out.
    Attachments:
    string_to_double.jpg ‏10 KB

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • How to return the same SUM value from two tables

    Hello,
    I have the following data:
    SQL> SELECT * FROM t1;
         T1_ID   T1_VALUE
             1        500
             1        500
    SQL> SELECT * FROM t2;
         T2_ID   T2_VALUE
             1       1000
    SQL> SELECT t1_id, SUM(t1_value), SUM(t2_value)
      2    FROM t1, t2
      3   WHERE t1_id = t2_id
      4   GROUP BY t1_id;
         T1_ID SUM(T1_VALUE) SUM(T2_VALUE)
             1          1000          2000How is it possible that SUM(T2_VALUE) returns also 1000.
    Thank you

    Here's one way:
    with t1 as (select 1 t1_id, 500 t1_value from dual union all
                select 1 t1_id, 500 t1_value from dual),
         t2 as (select 1 t2_id, 1000 t2_value from dual)
    select t3.t3_id, t3.t3_sum, t4.t4_sum
    from   (select t1_id t3_id, sum(t1_value) t3_sum from t1
            group by t1_id) t3,
           (select t2_id t4_id, sum(t2_value) t4_sum from t2
            group by t2_id) t4
    where  t3.t3_id = t4.t4_id

  • How can i get first four highest values from a table

    suppose we have salary table and we need first 4 highest salaries in one query or attemp

    Or use an analytic:
    SQL> select ename, sal from emp;
    ENAME                       SAL
    SMITH                       800
    ALLEN                      1600
    WARD                       1250
    JONES                      2975
    MARTIN                     1250
    BLAKE                      2850
    CLARK                      2450
    SCOTT                      3000
    KING                       5000
    TURNER                     1500
    ADAMS                      1100
    JAMES                       950
    FORD                       3000
    MILLER                     1300
    14 rows selected.
    SQL> select ename, sal
      2  from
      3  (
      4     select ename
      5           ,sal
      6           ,dense_rank() over (order by sal desc) dr
      7     from   emp
      8  )
      9  where dr <= 4;
    ENAME                       SAL
    KING                       5000
    SCOTT                      3000
    FORD                       3000
    JONES                      2975
    BLAKE                      2850

  • What does the "second highest"mean on the macbook pro web page mean? If you have to think too hard then does it need changing as a landing page title ?

    An
    y comments ?

    thanks
    just seemed a strange turn of phrase.
    obviously worked though as I was puzzled enough to  ask :-)

  • Retreving Hexadecimal Values from a table using SQL query.

    Hi,
    I'm looking for a query to retreive Hexadecimal values contained in a column using SQL query.
    The column contains the values of all types, alphanumeric, numeric and hexadecimal.
    I need to retreive only hexadecimal values.
    any help to me in this regard will be appreciated.
    Thanks

    Presumably, you can be sure that any valid hex value is indeed MEANT to BE a hex value. For example the value 'ACE' is meant to be a hexadecimal value and not the word.

Maybe you are looking for

  • Error ocurring when trying to Backup catalog in PSE 7

    I am about to upgrade my OS and want to start fresh.  Obviously, I want to backup my PSE 7 catalog beforehand so I can restore it and not lose the thousands of tags, etc I have applied.  I have carefully followed the steps and even ran some utilities

  • Premiere CS4 Media Encoder AVIs and Encore Encoding Errors

    For some reason, I'm having trouble creating DVD's in Encore from AVI's exported from Premiere CS4. When encoding starts, Encore immediately pops up with an "encoding error". I now, all of a sudden get this identical error on two of our systems. Most

  • SOA 11g BAM - MS SQL

    Hi, I have installed the Oracle BAM and create a External Data Source to integrate with Microsoft SQL Server 2008. Everything occur well, but when i try to create a new Report i get this error: [FMWGEN][SQLServer JDBC Driver][SQLServer]Invalid object

  • Pricing Condition Type PR00.

    Hi experts, I have a scenario where condition type PR00 shoul be mandatory in sales order   and document should not proceed further unless the basic price  is put while creating sales order. Also,  system should not allow double entry of PR00. I have

  • Who's logged-in?

    How can I see/check who is logged-in? We are evaluating Final Cut Server and only have a 10-client license currently. How can I check who is connected if say 10 users are using the client? Is there a Leopard Server tool so I can see who is on the net