w3resource
SQL exercises

SQL Subquery Exercises: Display the first and last name, and department code for all employees who work in the department Marketing

SQL SUBQUERY: Exercise-41 with Solution

Write a query in SQL to display the first and last name, and department code for all employees who work in the department Marketing.

Sample table: employees


Sample table: departments


Sample Solution:

SELECT first_name, last_name, department_id 
 FROM employees 
   WHERE department_id = 
       (SELECT department_id 
          FROM departments 
           WHERE department_name = 'Marketing');

Sample Output:

first_name	last_name	department_id
Michael		Hartstein	20
Pat		Fay		20

Practice Online


Query Visualization:

Duration:

Query visualization of Display the first and last name, and department code for all employees who work in the department Marketing - Duration

Rows:

Query visualization of Display the first and last name, and department code for all employees who work in the department Marketing - Rows

Cost:

Query visualization of Display the first and last name, and department code for all employees who work in the department Marketing - Cost

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

Previous: Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary of the employee who works in that department which ID is 40.
Next: Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming