SQL query operator minus is not working

vankraster picture vankraster · Jan 21, 2011 · Viewed 7.5k times · Source
(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

Answer

Michael Pakhantsov picture Michael Pakhantsov · Jan 21, 2011

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)