SQL JOINS on HR Database: Display full name, job title, starting and ending date of last jobs for those employees worked without a commission percentage
SQL JOINS on HR Database: Exercise-25 with Solution
25. From the following tables, write a SQL query to find full name (first and last name), job title, starting and ending date of last jobs of employees who worked without a commission percentage.
Sample table: jobs
Sample table: job_history
Sample table: employees
Sample Solution:
SELECT CONCAT(e.first_name, ' ', e.last_name) AS Employee_name,
j.job_title,
h.*
FROM employees e
JOIN
(SELECT MAX(start_date),
MAX(end_date),
employee_id
FROM job_history
GROUP BY employee_id) h ON e.employee_id=h.employee_id
JOIN jobs j ON j.job_id=e.job_id
WHERE e.commission_pct = 0;
Sample Output:
employee_name job_title starting_date ending_date employee_id Neena Kochhar Administration Vice President 2001-10-28 2005-03-15 101 Lex De Haan Administration Vice President 2001-01-13 2006-07-24 102 Den Raphaely Purchasing Manager 2006-03-24 2007-12-31 114 Payam Kaufling Stock Manager 2007-01-01 2007-12-31 122 Jennifer Whalen Administration Assistant 2002-07-01 2006-12-31 200 Michael Hartstein Marketing Manager 2004-02-17 2007-12-19 201
Practice Online
Query Visualization:
Duration:
Rows:
Cost:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: From the following tables, write a SQL query to find full name (first and last name), and salary of those employees who work in any department located in 'London' city.
Next: From the following tables, write a SQL query to find the department name, department ID, and number of employees in each department.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
SQL Server SELECT into existing table.
INSERT INTO dbo.TABLETWO SELECT col1, col2 FROM dbo.TABLEONE WHERE col3 LIKE @search_key
This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:
INSERT INTO dbo.TABLETWO (col1, col2) SELECT col1, col2 FROM dbo.TABLEONE WHERE col3 LIKE @search_key
Database: SQL Server
Ref: https://bit.ly/3y6tpA3
- 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