RSS

How to get the single row having highest column value

07 Jun

Sometimes during interview a question has been asked. That how to get the single row which have certain column value highest or lowest without using any condition. Actually there are certain ways by which we can accomplish this. One way which i want to discuss with all of you is very simple. By using “ORDER BY” and “LIMIT” clause of MySQL.

mysql> SELECT employeeId FROM employees ORDER BY salary DESC LIMIT 1;

The above sql statement will provide us the single `employeeId` from table `employees` who have the highest salary.

 

 
Leave a comment

Posted by on June 7, 2011 in MySQL

 

Tags: , , , , ,

Leave a comment