w3resource

SQL Subquery Exercises: Display all the information of the employees whose salary if within the range of smallest salary and 2500

SQL SUBQUERY: Exercise-10 with Solution

From the following table and write a SQL query to find those employees whose salary falls within the range of the smallest salary and 2500. Return all the fields.

Sample table: employees


Sample Solution:

SELECT * 
FROM employees 
WHERE salary BETWEEN  
(SELECT MIN(salary) 
FROM employees) AND 2500;

Sample Output:

employee_id	first_name	last_name	email	phone_number	hire_date	job_id	salary	commission_pct	manager_id	department_id
119		Karen		Colmenares	KCOLMENA515.127.4566	2007-08-10	PU_CLERK	2500.00	0.00	114		30
127		James		Landry		JLANDRY	650.124.1334	2007-01-14	ST_CLERK	2400.00	0.00	120		50
128		Steven		Markle		SMARKLE	650.124.1434	2008-03-08	ST_CLERK	2200.00	0.00	120		50
131		James		Marlow		JAMRLOW	650.124.7234	2005-02-16	ST_CLERK	2500.00	0.00	121		50
132		TJ		Olson		TJOLSON	650.124.8234	2007-04-10	ST_CLERK	2100.00	0.00	121		50
135		Ki		Gee		KGEE	650.127.1734	2007-12-12	ST_CLERK	2400.00	0.00	122		50
136		Hazel		Philtanker	HPHILTAN650.127.1634	2008-02-06	ST_CLERK	2200.00	0.00	122		50
140		Joshua		Patel		JPATEL	650.121.1834	2006-04-06	ST_CLERK	2500.00	0.00	123		50
144		Peter		Vargas		PVARGAS	650.121.2004	2006-07-09	ST_CLERK	2500.00	0.00	124		50
182		Martha		Sullivan	MSULLIVA650.507.9878	2007-06-21	SH_CLERK	2500.00	0.00	120		50
191		Randall		Perkins		RPERKINS650.505.4876	2007-12-19	SH_CLERK	2500.00	0.00	122		50

Pictorial Presentation:

SQL Subqueries: Display all the information of the employees whose salary if within the range of smallest salary and 2500

Practice Online


Query Visualization:

Duration:

Query visualization of Display all the information of the employees whose salary if within the range of smallest salary and 2500 - Duration

Rows:

Query visualization of Display all the information of the employees whose salary if within the range of smallest salary and 2500 - Rows

Cost:

Query visualization of Display all the information of the employees whose salary if within the range of smallest salary and 2500 - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to find those employees whose salary is in the range 1000, and 3000 (Begin and end values have included.). Return all the fields.
Next: From the following tables, write a SQL query to find those employees who do not work in those departments where manager ids are in the range 100, 200 (Begin and end values are included.) Return all the fields of the employees.

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