Georgi Michev
Georgi Michev

Reputation: 894

SQL getting values from one table excluding others with minus

I must create a query that finds all employee names and salary where the salary is between 2000 and 15000 but not in the range of 5000 and 10000

I am trying to do it with the minus operator and it looks just like examples in all tutorials but it doesnt work

select first_name, last_name, salary from hr.employees where salary between 2000 and 15000
minus
select first_name, last_name, salary from hr.employees where salary not between 5000 and 10000

MySQL workbench also says minus is not valid at this position

Upvotes: 0

Views: 32

Answers (1)

Kondybas
Kondybas

Reputation: 696

MySQL does not support the minus operator at all. You have to emulate its behaviour.

SELECT first_name, last_name, salary 
  FROM hr.employees 
 WHERE salary BETWEEN 2000 AND 15000
   AND salary NOT BETWEEN 5000 AND 10000

Upvotes: 3

Related Questions