w3resource
SQL exercises

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

SQL SUBQUERY: Exercise-35 with Solution

Write a query in SQL to display the department code and name for all departments which located in the city London.

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

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: Write a query to display the employee id, name ( first name and last name ), salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003.
Next: Write a query in SQL to display the first and last name, salary, and department ID for all those employees who earn more than the average salary and arrange the list in descending order on salary.

What is the difficulty level of this exercise?



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