w3resource

SQL Subquery Exercises: Display the first and last name, salary and department ID for those employees whose department is located in the city London

SQL SUBQUERY: Exercise-46 with Solution

From the following tables, write a SQL query to find all employees whose department is located in London. Return first name, last name, salary, and department ID.

Sample table: employees


Sample table: departments


Sample table: locations


Sample Solution:

SELECT first_name, last_name, salary, department_id 
  FROM employees
    WHERE department_id IN 
          (SELECT department_id 
            FROM departments 
             WHERE location_id = 
               (SELECT location_id 
                 FROM locations 
                   WHERE city = 'London'));

Sample Output:

first_name	last_name	salary	department_id
Susan		Mavris		6500.00	40

Pictorial Presentation:

SQL Subqueries Exercises: Display the first and last name, salary and department ID for those employees whose department is located in the city London.

Practice Online


Query Visualization:

Duration:

Query visualization of Display the first and last name, salary and department ID for those employees whose department is located in the city London - Duration

Rows:

Query visualization of Display the first and last name, salary and department ID for those employees whose department is located in the city London - Rows

Cost:

Query visualization of Display the first and last name, salary and department ID for those employees whose department is located in the city London - Cost

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

Previous: From the following table, write a SQL query to find those employees who earn less than the average salary, and work at the department where the employee 'Laura' (first name) works. Return first name, last name, salary, and department ID.
Next: From the following tables, write a SQL query to find the city of the employee of ID 134. Return city.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

"where 1=1" statement?

It's usually when folks build up SQL statements.

When you add and value = "Toyota" you don't have to worry about whether there is a condition before or just WHERE.

Ref: https://bit.ly/3cayyhJ