SQL Queries: Query for getting Second highest number record

Query for getting Second Highest Number Record from a Table


Getting Second highest Marks from table
Two SQL commands will be used to get the second highest number from the table

1. Order by
2. Limit
First we will order the numbers in descending order by using Order By command so that we can get the highest number at the first position(first row) and second highest at the second position(second row) in the table.

Next we will use Limit command to display second highest number as Limit command is used to display some part of the records returned by a query specifying a range.

SQL Query:
SELECT *
FROM student
ORDER BY marks DESC
LIMIT 1,1;

Comments

  1. hey can we talk for a while ? i am QA-SQL guy frm Teradata ...

    ReplyDelete
  2. Question :::::

    Display the full name of all employees with either an "E" or "S" in their last name.

    ReplyDelete
  3. this could be solved by sub query as
    select max(result)
    from marks
    where marks < (

    select max(result)
    from marks
    )
    // Here inner query will result hieghest results from table marks,and out query will give second hieghest.

    ReplyDelete
  4. ok Sure messagepk ... add me on skype if u need any help

    shumaila_afzal

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Lose Weight: Fast Way of Losing Weight

SQL Tutorial