w3resource

SQL Subquery Exercises: Determine who earns more than Mr. Ozer

SQL SUBQUERY: Exercise-29 with Solution

From the following table, write a SQL query to find all those employees who earn more than an employee whose last name is 'Ozer'. Sort the result in ascending order by last name. Return first name, last name and salary.

Sample table: employees


Sample Solution:

SELECT first_name, last_name, salary 
FROM employees 
WHERE salary > 
(SELECT salary 
FROM employees 
WHERE last_name='Ozer') 
ORDER BY  last_name;

Sample Output:

first_name	last_name	salary
Lex		De Haan		17000.00
Alberto		Errazuriz	12000.00
Nancy		Greenberg	12000.00
Michael		Hartstein	13000.00
Shelley		Higgins		12000.00
Steven		King		24000.00
Neena		Kochhar		17000.00
Karen		Partners	13500.00
John		Russell		14000.00

Pictorial Presentation:

SQL Subqueries: Determine who earns more than Mr. Ozer.

Practice Online


Query Visualization:

Duration:

Query visualization of Determine who earns more than Mr. Ozer - Duration

Rows:

Query visualization of Determine who earns more than Mr. Ozer - Rows

Cost:

Query visualization of Determine who earns more than Mr. Ozer - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following table, write a SQL query to find those employees who earn more than average salary and who work in any of the ‘IT’ departments. Return last name.
Next: From the following tables, write a SQL query to find those employees who work under a manager based in ‘US’. Return first name, last name.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

How to count occurrences of a column value in SQL?

Input table:

id | age
--------
0  | 25
1  | 25
2  | 23
SELECT age, count(age) 
  FROM Students 
 GROUP by age

Output:

id | age | count
----------------
0  | 25  | 2
1  | 25  | 2
2  | 23  | 1

Ref: https://bit.ly/3zbLPQm