w3resource
SQL exercises

SQL Subquery Exercises: Display all the information of the employees whose salary is within the range 1000 and 3000

SQL SUBQUERY : Exercise-9 with Solution

Write a query to display all the information of the employees whose salary is within the range 1000 and 3000.

Sample table: employees


Sample Solution:

SELECT * FROM employees 
WHERE salary BETWEEN 1000 and 3000;

or

SELECT * 
FROM employees 
WHERE salary BETWEEN (SELECT 1000) AND 3000;

Sample Output:

employee_id	first_name	last_name	email	phone_number	hire_date	job_id	salary	commission_pct	manager_id	department_id
116		Shelli		Baida		SBAIDA	515.127.4563	2005-12-24	PU_CLERK	2900.00	0.00	114		30
117		Sigal		Tobias		STOBIAS	515.127.4564	2005-07-24	PU_CLERK	2800.00	0.00	114		30
118		Guy		Himuro		GHIMURO	515.127.4565	2006-11-15	PU_CLERK	2600.00	0.00	114		30
119		Karen		Colmenares	KCOLMENA515.127.4566	2007-08-10	PU_CLERK	2500.00	0.00	114		30
126		Irene		Mikkilineni	IMIKKILI650.124.1224	2006-09-28	ST_CLERK	2700.00	0.00	120		50
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
130		Mozhe		Atkinson	MATKINSO650.124.6234	2005-10-30	ST_CLERK	2800.00	0.00	121		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
134		Michael		Rogers		MROGERS	650.127.1834	2006-08-26	ST_CLERK	2900.00	0.00	122		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
139		John		Seo		JSEO	650.121.2019	2006-02-12	ST_CLERK	2700.00	0.00	123		50
140		Joshua		Patel		JPATEL	650.121.1834	2006-04-06	ST_CLERK	2500.00	0.00	123		50
143		Randall		Matos		RMATOS	650.121.2874	2006-03-15	ST_CLERK	2600.00	0.00	124		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
183		Girard		Geoni		GGEONI	650.507.9879	2008-02-03	SH_CLERK	2800.00	0.00	120		50
187		Anthony		Cabrio		ACABRIO	650.509.4876	2007-02-07	SH_CLERK	3000.00	0.00	121		50
190		Timothy		Gates		TGATES	650.505.3876	2006-07-11	SH_CLERK	2900.00	0.00	122		50
191		Randall		Perkins		RPERKINS650.505.4876	2007-12-19	SH_CLERK	2500.00	0.00	122		50
195		Vance		Jones		VJONES	650.501.4876	2007-03-17	SH_CLERK	2800.00	0.00	123		50
197		Kevin		Feeney		KFEENEY	650.507.9822	2006-05-23	SH_CLERK	3000.00	0.00	124		50
198		Donald		OConnell	DOCONNEL650.507.9833	2007-06-21	SH_CLERK	2600.00	0.00	124		50
199		Douglas		Grant		DGRANT	650.507.9844	2008-01-13	SH_CLERK	2600.00	0.00	124		50

Practice Online


Query Visualization for Sample Solution:

Duration:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Duration

Rows:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Rows

Cost:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Cost

Query Visualization for alternate Sample Solution:

Duration:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Duration

Rows:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Rows

Cost:

Query visualization of Display all the information of the employees whose salary is within the range 1000 and 3000 - Cost

Contribute your code and comments through Disqus.

Previous: Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.
Next: Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500.

What is the difficulty level of this exercise?



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