w3resource

SQL JOINS on HR Database: Display the full name of employee with ID and present country where (s)he is working

SQL JOINS on HR Database: Exercise-27 with Solution

27. From the following tables, write a SQL query to find the full name (first and last name) of the employee with ID and name of the country presently where he/she is working.

Sample table: countries


Sample table: locations


Sample table: employees


Sample table: departments


Sample Solution:

SELECT employee_id, job_title, end_date-start_date DAYS 
	FROM job_history
		NATURAL JOIN jobs 
			WHERE department_id=80;

Sample Output:

employee_id	job_title	days
176	Sales Manager	364
176	Sales Representative	282

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the full name of employee with ID and present country where (s)he is working - Duration

Rows:

Query visualization of Display the full name of employee with ID and present country where (s)he is working - Rows

Cost:

Query visualization of Display the full name of employee with ID and present country where (s)he is working - 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 the department name, department ID, and number of employees in each department.
Next: SQL UNION Exercises Home

What is the difficulty level of this exercise?