user4220563
user4220563

Reputation:

Query with EXCEPT throws an error

MySQL keeps throwing errors when I try to use the SQL except in my query...

Why isn't it working? What's wrong with it?

select name, email from users
except
select name, email from users_ban

Upvotes: 4

Views: 45

Answers (1)

jpw
jpw

Reputation: 44881

As far as I know MySQL does not support theexceptstatement. You can use query with a correlatednot existspredicate to the same effect like this:

SELECT DISTINCT *
  FROM users
  WHERE NOT EXISTS ( 
                    SELECT 1
                      FROM users_ban
                      WHERE users.name
                            = 
                            users_ban.name
                        AND users.email
                            = 
                            users_ban.email );

Sample SQL Fiddle

Upvotes: 1

Related Questions