w3resource

SQL Subquery Exercises: Display the department code and name for all departments which located in the city London

SQL SUBQUERY: Exercise-35 with Solution

From the following tables, write a SQL query to find those departments that are located in the city of London. Return department ID, department name.

Sample table: departments


Sample table: locations


Sample Solution:

SELECT department_id, department_name 
  FROM departments 
    WHERE location_id = 
            (
              SELECT location_id 
                FROM locations 
                  WHERE city = 'London'
            );

Sample Output:

department_id	department_name
40		Human Resources

Pictorial Presentation:

SQL Subqueries: Display the department code and name for all departments which located in the city London.

Practice Online


Query Visualization:

Duration:

Query visualization of Display the department code and name for all departments which located in the city London - Duration

Rows:

Query visualization of Display the department code and name for all departments which located in the city London - Rows

Cost:

Query visualization of Display the department code and name for all departments which 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 get such a salary, which is the maximum of salaried employee, joining within January 1st, 2002 and December 31st, 2003. Return employee ID, first name, last name, salary, department name and city.
Next: From the following table, write a SQL query to find those employees who earn more than the average salary. Sort the result-set in descending order by salary. Return first name, last name, salary, and department ID.

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