Reputation: 347
can MySQL use Set operation intersect
(∩) and except
(-)?
if can,please give a example
if can't, then what's the operation instead?
Upvotes: 3
Views: 8102
Reputation: 1323
Mysql does not support intersect and except, but you can achive this in other way.
Intersect:
SELECT a.x, a.y FROM a JOIN b ON a.x = b.x AND a.y = b.y;
Except:
SELECT a.* FROM a WHERE NOT EXISTS (SELECT 1 FROM b WHERE b.x = a.x)
Upvotes: 0
Reputation: 1841
It is possible to use intersect in mysql, but you have to write it a little differently. Here an example (and here a link to a nice description):
SELECT a.member_id, a.name
FROM a INNER JOIN b
USING (member_id, name)
You can find an example for except (minus) in the page also
Upvotes: 2