Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL Subquery Exercises: Find the name and salary of the employees who earns more than the employee whose last name is Bell

MySQL Subquery: Exercise-8 with Solution

Write a query to find the name (first_name, last_name), and salary of the employees who earns more than the employee whose last name is Bell.

Sample table: employees


Sample table : departments


Code:

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

Explanation:

MySQL Subquery Syntax:

MySQL subquery syntax

- The subquery (inner query) executes once before the main query (outer query) executes.
- The main query (outer query) use the subquery result.

MySQL SubQueries:Find the names, salary of the employees who earns more than the employee whose last name is Bell.

 

MySQL Code Editor:

Structure of 'hr' database :

hr database

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

Previous:Write a query to find the name (first_name, last_name), and salary of the employees who earns more than the average salary and works in any of the IT departments.
Next:Write a query to find the name (first_name, last_name), and salary of the employees who earn the same salary as the minimum salary for all departments.

What is the difficulty level of this exercise?