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 have a higher salary than the employee whose last_name='Bull'

MySQL Subquery: Exercise-1 with Solution

Write a query to find the name (first_name, last_name) and the salary of the employees who have a higher salary than the employee whose last_name='Bull'.

Sample table: employees


Code:

SELECT FIRST_NAME, LAST_NAME, SALARY 
FROM employees 
WHERE SALARY > 
(SELECT salary FROM employees WHERE last_name = 'Bull');

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.

Write a query to find the names and salaries of the employees who have higher salary than the employee whose last_name='Bull'

Here the where comparison operator uses the '>' operator.

 

MySQL Code Editor:

Structure of 'hr' database:

hr database

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

Previous:MySQL Subquery
Next:Write a query to find the name (first_name, last_name) of all employees who works in the IT department.

What is the difficulty level of this exercise?