I am trying to compose a SELECT statement for MySQL that selects from table A something that does not exist in table B. For example:
Table a:
+------+
| BAND |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+------+
Table B:
+------+
| HATE |
+------+
| 1 |
| 5 |
+------+
So, if table A is all groups and table B is groups that I hate, then I only need groups that I DO NOT hate. Thus, the result of the selection should be:
+------+
| BAND |
+------+
| 2 |
| 3 |
| 4 |
+------+
How can I write one choice for this? Here is my last attempt:
SELECT * FROM A LEFT JOIN B ON A.BAND = B.HATE WHERE B.HATE IS NULL;
EDIT: The line above has been fixed! See Comments below ... "= NULL" versus "IS NULL".
source
share