w3resource

SQL Subquery Exercises: Display the detail information of departments which starting salary is at least 8000

SQL SUBQUERY: Exercise-49 with Solution

From the following tables, write a SQL query to find those departments where the starting salary is at least 8000. Return all the fields of departments.

Sample table: departments


Sample table: employees


Sample Solution:

SELECT * FROM departments 
	WHERE department_id IN 
		( SELECT department_id 
                   FROM employees 
			GROUP BY department_id 
				HAVING MIN(salary)>=8000);

Sample Output:

department_id	department_name	manager_id	location_id
70		Public Relations	204		2700
90		Executive		100		1700
110		Accounting		205		1700

Pictorial Presentation:

SQL Subqueries Exercises: Display the detail information of departments which starting salary is at least 8000.

Practice Online


Query Visualization:

Duration:

Query visualization of Display the detail information of departments which starting salary is at least 8000 - Duration

Rows:

Query visualization of Display the detail information of departments which starting salary is at least 8000 - Rows

Cost:

Query visualization of Display the detail information of departments which starting salary is at least 8000 - 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 those departments where maximum salary is 7000 and above. The employees worked in those departments have already completed one or more jobs. Return all the fields of the departments.
Next: From the following table, write a SQL query to find those managers who supervise four or more employees. Return manager name, 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