0

Have written below query:

mysql > select * from employees where Salary NOT IN (select Salary from employees limit 3);

Gives below error:

ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

marcell
  • 1,498
  • 1
  • 10
  • 22
  • 3
    Possible duplicate of [MySQL - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery](https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql-doesnt-yet-support-limit-in-all-any-some-subqu) – marcell Dec 25 '17 at 17:09

2 Answers2

0

There are 2 Problems in your Query. First is the Syntax and the second is that there is no ORDER BY in the LIMIT SELECT. If there is no ORDER the result can every time changed (Ramdom)

You can do it with a QUERY like this:

SELECT e.* FROM employees e WHERE e.salery NOT IN 
(SELECT * FROM (
    SELECT s.salery
    FROM employees s
    ORDER BY salery LIMIT 3) AS tmp)
ORDER BY e.salery ;

Here is my Sample:

MariaDB [bernd]> select * FROM employees;
+----+--------+--------+
| id | salery | name   |
+----+--------+--------+
|  1 |    100 | Bernd  |
|  2 |    500 | Peter  |
|  3 |    300 | Paul   |
|  4 |   1234 | Mary   |
|  5 |    800 | Erwin  |
|  6 |    777 | Hubert |
+----+--------+--------+
6 rows in set (0.00 sec)

MariaDB [bernd]>

MariaDB [bernd]> SELECT e.* FROM employees e WHERE e.salery NOT IN
    -> (SELECT * FROM (
    ->     SELECT s.salery
    ->     FROM employees s
    ->     ORDER BY salery LIMIT 3) AS tmp)
    -> ORDER BY e.salery ;
+----+--------+--------+
| id | salery | name   |
+----+--------+--------+
|  6 |    777 | Hubert |
|  5 |    800 | Erwin  |
|  4 |   1234 | Mary   |
+----+--------+--------+
3 rows in set (0.00 sec)
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39
0

Something like:

select employees.*
from employees
where (
   select count(*) from employees as e
   where e.Salary >= employees.Salary
) > 3;

...but depending on the table size/indexes, it may be too heavy for the server. SQL Fiddle: http://sqlfiddle.com/#!9/67754e/2

Oliver Maksimovic
  • 3,204
  • 3
  • 28
  • 44