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

Similar Messages

  • How to get 2 maximum salary from salary field?

    how to get 2 maximum salary from salary field data?
    like 1000
           5000
            8600
              2000
              3000
    u want 8600 in ist place and 5000 in second place ?
    cud u plz suggest me any query?

    Hi,
    If already data is in internal table then
    DATA : v_cnt TYPE i.
    SORT ITAB BY salary DESCENDING.
    LOOP AT ITAB.
       v_cnt = v_cnt + 1.
      IF v_cnt > 2.  
          EXIT.
      ENDIF.
    MOVE : itab-salary  to ITAB1.
    ENDLOOP.
    if you want extract data from database table then slect the data inot internal table and do like above.
    Pls. reward if useful...

  • How to get second maximum salary

    Hi,
    Can you let me know a query to get the second maximum salary. I'm using 9i Database and I'm not supposed to write any co-related sub querries.
    Suppose the sal's i've are
    EMP - Sal
    100 - 10000
    101 - 20000
    102 - 30000
    103 - 25000
    104 - 15000
    I want to retrive 103 only.
    Thanks in advance,
    Jai.

    Can you let me know a query to get the second maximum
    salary. I'm using 9i Database and I'm not supposed to
    write any co-related sub querries.
    Why not? Says who?
    SQL> select * from salaries;
           EMP        SAL
           100      10000
           101      20000
           102      30000
           103      25000
           104      15000
    SQL> SELECT emp
      2        ,sal
      3  FROM   (SELECT emp
      4                ,sal
      5                ,rank() OVER(ORDER BY sal DESC) AS rank
      6          FROM   salaries)
      7  WHERE  rank = 2
      8  /
           EMP        SAL
           103      25000
    SQL> Regards,
    Steve Rooney

  • How to get 3 maximum salaries from emp

    Hello,
    Dear fellows how can we get 3 maximum salaries from emp
    table in SQL.
    plz reply me soon
    thanks

    Does it work ?
    13:18:31 SQL> select * from my_tab1;
    A B
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    8 rows selected.
    13:19:24 SQL> ed
    Wrote file afiedt.buf
    1 SELECT UNIQUE a FROM my_tab1 WHERE a>=
    2 (SELECT MAX(a) FROM my_tab1 WHERE a<
    3 (SELECT MAX(a) FROM my_tab1 WHERE a <
    4* (SELECT MAX(a) FROM my_tab1)))
    13:19:34 SQL> /
    no rows selected

  • How to find 'n' th maximum salary in employees table

    how to find 'n' th maximum salary in employees table using stored procedure............

    Depends on your unmentioned database version.
    In general you're asking for a Top-N query.
    See this article:
    http://www.oracle.com/technetwork/issue-archive/2007/07-jan/o17asktom-093877.html
    In 11g you have http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions114.htm#CJAFEJBE
    an analytic function
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#SQLRF06174

  • 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

  • How to get edited row values from ADF table?

    JDev 11.
    I have a table which is populated with data from Bean.
    I need to save changes after user make changes in any table cell. InputText is defined for table column component.
    I have defined ValueChangeListener for inputText field and AutoSubmit=true. So when user change value in inputText field, method is called:
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    getSelectedRow();
    SaveMaterial(material);
    This method should call getSelectedRow which take values from selected table row and save them into object:
    private Row getSelectedRow(){
    RichTable table = this.getMaterialTable();
    Iterator selection = table.getSelectedRowKeys().iterator();
    while (selection.hasNext())
    Object key = selection.next();
    table.setRowKey(key);
    Object o = table.getRowData();
    material = (MATERIAL) o;
    System.out.println("Selected Material Desc = "+material.getEnumb());
    return null;
    Problem is that getSelectedRow method doesnt get new (edited) values, old values are still used.
    I have tried to use ActiveButton with same method and it works fine in that case. New values are selected from active row and inserted into object.
    JSF:
    <af:table var="row" rowSelection="single" columnSelection="single"
    value="#{ManageWO.material}" binding="#{ManageWO.materialTable}">
    <af:column sortable="false" headerText="E-number">
    <af:inputText value="#{row.enumb}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    <af:column sortable="false" headerText="Description">
    <af:inputText value="#{row.desc}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    </af:table>
    <af:activeCommandToolbarButton text="Save" action="#{ManageWO.EditData}"/>
    What is a correct place from where save method should be called to get new (edited) values from ADF table?
    Thanks.

    Did you look into the valueChangeEvent?
    It has oldValue and newValue attributes.
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    Object oldVal = valueChangeEvent.getOldValue();
    Object newVal = valueChangeEvent.getNewValue();
    // check if you see what you are looking for.....
    getSelectedRow();
    SaveMaterial(material);
    }Timo

  • How to get tax break up of TDS using SQL query ?

    Hi all,
    We are developing a TDS report using SQL query
    Report will contain VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount,
    Bill Value – 100.000,
    TDS (2%) - 2.000,
    TDS Surcharge(10% on TDS) - 0.2,
    TDS Cess(2%(TDS+TDS Surcharge)) - 0.044,
    TDS HeCess(1%(TDS+TDS Surcharge)) - 0.022.
    We have developed this report which displays upto
    VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount.
    How to show tax break up of TDS in SQL query ?
    Thanks,
    With regards,
    Jeyakanthan.

    Hi gauraw,
    Thank for your reply.
    I modified the query , pasted the query
    as below in query generator,
    Select T0.DocNum,T0.DocDate,T0.CardCode as 'Ledger',T1.TaxbleAmnt As 'Bill value',T1.WTAmnt as 'TDSAmt',(TDSAmt * 0.1) as 'TDS_Surch',
    (((TDSAmt0.1) + TDSAmt)0.02)  as 'TDSCess',
    (((TDSAmt0.1) + TDSAmt)0.01)  as 'TDSHCess'
    FROM OPCH T0  INNER JOIN PCH5 T1 ON T0.DocEntry = T1.AbsEntry
    WHERE (T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]')
    on clicking execute its showing error message invalid column
    name 'TDSAmt'.
    With regards,
    Jeyakanthan

  • How to get the row difference from two tables

    I am not good at SQL. Here is a problem I am having
    I have two tables say Employee_Master and Employee_Today. Employee_Today table is basically a subset of Empolyee_Master. At a given time, I want to query the database and and get all the employee names from Employee_Master table that are NOT in the Employees_Today table. How would I write that?
    Select a.name from Employee_Master a, Employee_Today b where ..........?
    Thanks for suggstions

    if i understand your requirement correctly try this:
    Select a.name from Employee_Master a
    Where  Not Exists
          (Select 'x' From Employee_Today b
           Where  b.name = a.name) ;hope this helps

  • How to get Hierarchical XML File from a Database Join Query !

    Hi,
    How can i get a Hierarchical XML File from a Database Join Query ?
    Any join query returns repeated values as below:
    BD17:SQL>select d.dname, e.ename, e.sal
    2 from dept d
    3 natural join
    4 emp e
    5 /
    DNAME ENAME SAL
    ACCOUNTING CLARK 2450
    ACCOUNTING KING 5000
    ACCOUNTING MILLER 1300
    RESEARCH SMITH 800
    RESEARCH ADAMS 1100
    RESEARCH FORD 3000
    RESEARCH SCOTT 3000
    RESEARCH JONES 2975
    SALES ALLEN 1600
    SALES BLAKE 2850
    SALES MARTIN 1250
    SALES JAMES 950
    SALES TURNER 1500
    SALES WARD 1250
    14 rows selected.
    We tried use DBMS_XMLQUERY to generate a xml file, but it was unable to get xml in Hierarchical format.
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    - <ROWSET>
    - <ROW num="1">
    <DNAME>ACCOUNTING</DNAME>
    <ENAME>CLARK</ENAME>
    <SAL>2450</SAL>
    </ROW>
    - <ROW num="2">
    <DNAME>ACCOUNTING</DNAME>
    <ENAME>KING</ENAME>
    <SAL>5000</SAL>
    </ROW>
    - <ROW num="3">
    <DNAME>ACCOUNTING</DNAME>
    <ENAME>MILLER</ENAME>
    <SAL>1300</SAL>
    </ROW>
    - <ROW num="4">
    <DNAME>RESEARCH</DNAME>
    <ENAME>SMITH</ENAME>
    <SAL>800</SAL>
    </ROW>
    - <ROW num="5">
    <DNAME>RESEARCH</DNAME>
    <ENAME>ADAMS</ENAME>
    <SAL>1100</SAL>
    </ROW>
    - <ROW num="6">
    <DNAME>RESEARCH</DNAME>
    <ENAME>FORD</ENAME>
    <SAL>3000</SAL>
    </ROW>
    - <ROW num="7">
    <DNAME>RESEARCH</DNAME>
    <ENAME>SCOTT</ENAME>
    <SAL>3000</SAL>
    </ROW>
    - <ROW num="8">
    <DNAME>RESEARCH</DNAME>
    <ENAME>JONES</ENAME>
    <SAL>2975</SAL>
    </ROW>
    - <ROW num="9">
    <DNAME>SALES</DNAME>
    <ENAME>ALLEN</ENAME>
    <SAL>1600</SAL>
    </ROW>
    - <ROW num="10">
    <DNAME>SALES</DNAME>
    <ENAME>BLAKE</ENAME>
    <SAL>2850</SAL>
    </ROW>
    - <ROW num="11">
    <DNAME>SALES</DNAME>
    <ENAME>MARTIN</ENAME>
    <SAL>1250</SAL>
    </ROW>
    - <ROW num="12">
    <DNAME>SALES</DNAME>
    <ENAME>JAMES</ENAME>
    <SAL>950</SAL>
    </ROW>
    - <ROW num="13">
    <DNAME>SALES</DNAME>
    <ENAME>TURNER</ENAME>
    <SAL>1500</SAL>
    </ROW>
    - <ROW num="14">
    <DNAME>SALES</DNAME>
    <ENAME>WARD</ENAME>
    <SAL>1250</SAL>
    </ROW>
    </ROWSET>
    Thank you for some help.
    Nelson Alberti

    Hi,
    I wrote a general ABAP program which can be configured to grab contrent from an URL and post that content as a new PI message into the integration adapter .... from that point on normal PI configuration can be used to route it to anywhere ...
    It can be easily scheduled as a background job to grab content on a daily basis etc ...
    Regards,
    Steven

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • How to get the insert scripts from a table data

    hi all,
    i want insert scripts for 100 records from a table.
    suppose i have a table xyz
    xyz:
    id name
    1 abc
    2 def
    i should get insert script for 100 rows like
    insert into xyz(id,name) values (1,'abc');
    insert into xyz(id,name) values (2,'def');
    i want 100 records data from all the tables from my database.
    thanks in advance to all.

    SQL> create table xyz (id number, name varchar2(10));
    Table created.
    SQL> insert into xyz values(1,'abc');
    1 row created.
    SQL> insert into xyz values(2,'def');
    1 row created.
    SQL> select 'insert into xyz values(id,name) values('||id||','''||name||''');' from xyz;
    'INSERTINTOXYZVALUES(ID,NAM
    insert into xyz values(id,name) values(1,'abc');
    insert into xyz values(id,name) values(2,'def');
    SQL>- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • How to get input text values from adf table - Urgent

    Hi Friends,
    This is my requirement. I designed customized master - detail - detail page. I customized the page in below format.
    1. Master Data Field (Input text,etc) .
    2. Detail in table format ( Rows are mapped to child table) and i given two buttons for to create row and delete row. I designed the table based on the example provided in forum for to create customized table. The input text component is mapped to the rows.
    Now i want to retrieve all the data's entered in the rows. The table is mapped to child table. When i read the values from the table its showing null.
    If any one faced this problem and fixed it, please send me the solution.
    Thanks & Regards
    VB

    Did you look into the valueChangeEvent?
    It has oldValue and newValue attributes.
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    Object oldVal = valueChangeEvent.getOldValue();
    Object newVal = valueChangeEvent.getNewValue();
    // check if you see what you are looking for.....
    getSelectedRow();
    SaveMaterial(material);
    }Timo

  • How to pull Roles and Policies from backend using SQL query in OIA

    Hello,
    I have Roles and Policies defined in OIA with mapping each other and there is no direct extract report from OIA Web console.
    Is there any oracle SQL query by which we can get the data and filter the Policies based on the role ?
    Note: We have one Role having more than one Polcies defined in OIA.
    Appreciate your help.
    Thanks

    I am quoting this from MOS Doc Id "Why would multiple session records be present in the User Sessions screen in P6 Web, and why might some of them have different IP addresses? (Doc ID 1600172.1)"
    Multiple sessions show up for users since different sections of P6 Web have their own sessions associated with them. If a user is authorized to use multiple areas of the software they will have multiple sessions each time they log in. Additionally, if users are closing their browsers before logging out of P6 Web Access you might see some past sessions still appearing in the list. These will eventually be cleared out by background jobs, however you can also reset the sessions in the software by clicking the "Reset User" link (Administer > User Sessions > Manage User Sessions), or by choosing the "Reset All Users" link (Administer > User Sessions > Manage User Sessions) to do this for all past sessions.
    Multiple IP addresses for sessions can happen when a user logs in from different machines. For example, a person may login at their desk, but then go to a colleagues workstation to discuss a project, and log in from there. Doing so will leave them with multiple IP addresses in the session records.
    Hope this helps
    Regards,
    Sachin Gupta

  • How to get thr number of rows of an SQL query in JSTL

    hi guys,
    can anyone please tell me how do i perform a function which finds out the particular rownumber of an sql query in JSTL.....
    the same code in jsp is:
    <% plateRSet.getRowNum() %>
    how do i do this given plateRset is the var for a given iteration
    thanks
    rahul

    make your result set scrollable...Not such a good idea. With Oracle, the JDBC driver will read and cache all the ResultSet in memory (with other DBMSs/drivers the behavior will probably be different, but you will still have some unnecessary overhead).
    You can do the caching yourself if you think it's worth it. If the piece of code you posted is why you need this for, then use a List or Vector and you won't need to know the size upfront.
    Alin,
    The jTDS Project.

Maybe you are looking for

  • EXPORT IN 10g is not working

    hi Guru's when i am trying to run expdp command i am getting following error [oracle@localhost ~]$ echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/home/oracle/oracle/product

  • WHEN will online number be available in CANADA?

    I would love to have this functionality with Skype.  Ideally, I'd like to have an Alberta area code (403, 587 or 780) or British Columbia area code (250)... Is this ever going to happen?  In the near future???  Thanks to anyone that might have an ans

  • Is a time capsule a good idea for a college student living in a dorm?

    Is a time capsule a good idea for a college student living in a dorm?

  • Calling Ldb

    Hi Experts Can i call 2 logical database screens in one program. my requirement is i have to combine to standard programs as one program ,but problem is each standard program of first 2 selection screen blocks is calling through  logical data base se

  • How to keep high res when I create a pdf from Publisher doc

    I created a pdf from a Publisher document, and the resolution is less than 300 dpi (about 500KB). The 1/2 page document is over 4MG as a Publisher document, so why did I lose resolution & what can I do to keep the resolution above 300? I tried 3 diff