SELECT * FROM boys WHERE boys.id NOT IN (SELECT DISTINCT boyfriend_id FROM beauty)
Sql statement upper beauty shows results of the query boyfriend_id present case as a null value
And use the Exists
SELECT * FROM boys WHERE NOT EXISTS (SELECT DISTINCT boyfriend_id FROM beauty WHERE boys.`id`=beauty.`boyfriend_id` )
You can not properly check out the girlfriend of the boy table id
The reason is simple: Because how can not be NULL "Operation"
- If the null participation of arithmetic, the arithmetic expression is null. (For example: +, -, *, / arithmetic)
- If the null involved in the comparison operation, the result can be considered false. (E.g.,:> =, <=, <> is greater than, less than, not equal)
- If the null operation involved in aggregation, the aggregate functions are set to null (used ISNULL (field 0), etc. This can be avoided). In addition count (*), count (1), outside the count (0) and the like (COUNT (field) field is null row count is not involved).
- If in time the subquery has a null value, the data is not returned not.