Php – SQL query operator minus is not working

exceptMySQLPHP

(SELECT IDOperatore FROM operatore) MINUS 
(SELECT IDOperatore FROM commessaoperatore GROUP BY IDOperatore)  

This query is no working, even if I try to replace MINUS with EXCEPT.
The singular query SELECT IDOperatore FROM operatore and SELECT IDOperatore FROM commessaoperatore GROUP BY IDOperatore are working, but if I try to put together with Minus operator they don't work.

ERROR: #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MINUS (SELECT IDOperatore FROM commessaoperatore GROUP BY IDOperatore)' at line 1

Best Answer

MINUS does not exists in mysql

however for you query you can use NOT EXISTS:

SELECT IDOperatore FROM operatore o
WHERE NOT EXISTS (SELECT 1
                 FROM commessaoperatore c 
                 WHERE c.IDOperatore = o.IDOperatore)