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 :
- The subquery (inner query) executes once before the main query (outer query) executes.
- The main query (outer query) use the subquery result.
Here the where comparison operator uses the '>' operator.
MySQL Code Editor:
Structure of '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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework