Saturday, September 20, 2014

Select secound highest value through query

Select secound highest value through query



SELECT id FROM (select id from listings order by id asc limit 1) as listi order by id limit 1


SELECT MAX( col )
  FROM table
 WHERE col < ( SELECT MAX( col )
                 FROM table )
 
 
 
SELECT MAX(col) FROM table WHERE col NOT IN (SELECT MAX(col) FROM table);
 
 
select col
from (
    select ROW_NUMBER() over (order by col asc) as 'rowNum', col
    from [table] ) withRowNum 
where rowNum = 2
 
 
 
SELECT `column` 
FROM `table` 
GROUP BY `column` 
ORDER BY `column` 
DESC LIMIT 1,1
 
 
SELECT * FROM Table ORDER BY NumericalColumn DESC LIMIT 1 OFFSET 1
 
 
SELECT *
FROM TableName a
WHERE
  2 = (SELECT count(DISTINCT(b.ColumnName))
       FROM TableName b WHERE
       a.ColumnName <= b.ColumnName);
 
 
 
select * from (select ROW_NUMBER() over (Order by Col_x desc) as Row, Col_1
    from table_1)as table_new tn inner join table_1 t1
    on tn.col_1 = t1.col_1
where row = 2
 
 
 
SELECT DISTINCT value FROM Table ORDER BY value DESC LIMIT 2
 
 
 
SELECT MIN(value) FROM (SELECT DISTINCT value FROM Table ORDER BY value DESC LIMIT 2) AS t
 
 
 
       
SELECT * FROM EMP
WHERE salary=
        (SELECT MAX(salary) FROM EMP
           WHERE salary != (SELECT MAX(salary) FROM EMP)
        );
 
 
 
select MAX(salary) as SecondMax from test where salary !=(select MAX(salary) from test)
 
 
 
 
 Code By : Dharambir Singh

 
 
 

No comments:

Post a Comment

Dharamart.blogspot.in