Wednesday, December 15, 2010

How to get "set A - set B" in MySQL

How to get "set A - set B" in MySQL.

A is a table. Like a group of members.
B is a table. Like a woman list of people.

A has fields. "name, role, ...".
B has fields. "name, sex (= only woman), age, ...".

We want to get "set A - set B".
This is, in set operation, "A inter (not B)".
Also, this is "Not woman subet of A".

And the SQL is:
"SELECT * FROM A LEFT JOIN B ON A.name = B.name WHERE B.name is null;"

No comments:

Post a Comment