Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Error in Syntax near except

I'm trying to select persons who have an account at all branches of the city. (With a SQL query)

SELECT A.customId 
FROM accountholder as A 
WHERE NOT EXISTS ( 
                   (SELECT name 
                    FROM branch 
                    WHERE city='LA') 
EXCEPT (SELECT C.branch 
        FROM accountholder AS B, account AS C 
        WHERE B.accountnumber = C.accountnumber 
              AND A.customId = B.customId)); 

Now I got:

ERROR 1064 (42000): 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 'EXCEPT (SELECT C.branch FROM accountholder AS B, account AS C WHERE B.accountnumber=' at line 1

And I do not see the problem. Am I blind or just stupid?

Thanks for help.

like image 871
haskellnoob Avatar asked Sep 09 '26 07:09

haskellnoob


1 Answers

MySQL does not use EXCEPT. Use NOT IN.

SELECT A.customId 
FROM accountholder as A 
WHERE branch NOT IN ( 
(SELECT name FROM branch WHERE city='LA') 
AND branch NOT IN (SELECT C.branch FROM accountholder AS B, account AS C WHERE B.accountnumber = C.accountnumber AND A.customId = B.customId)); 
like image 195
John Conde Avatar answered Sep 11 '26 22:09

John Conde