SELECT *
FROM openorders_tracking
WHERE id NOT IN (SELECT tracking_id FROM openorders_commission)
SELECT *
FROM openorders_tracking
LEFT JOIN openorders_commission
ON openorders_tracking.id=openorders_commission.tracking_id
WHERE openorders_commission.id IS NULL
I'm wondering both specifically for this query, and in general if there is a significant difference.
I don't have any data yet, nor indexes yet. I guess it's more in general if "NOT IN" is better than a JOIN or vice-versa.
For those who like EXPLAIN, here is the results for now (again, no indexes yet besides the primaries):
mysql> explain SELECT * FROM openorders_tracking WHERE id NOT IN (SELECT trackin
g_id FROM openorders_commission);
+----+--------------------+-----------------------+--------+---------------+----
--+---------+------+------+---------------------+
| id | select_type | table | type | possible_keys | key
| key_len | ref | rows | Extra |
+----+--------------------+-----------------------+--------+---------------+----
--+---------+------+------+---------------------+
| 1 | PRIMARY | openorders_tracking | ALL | NULL | NUL
L | NULL | NULL | 341 | Using where |
| 2 | DEPENDENT SUBQUERY | openorders_commission | system | NULL | NUL
L | NULL | NULL | 0 | const row not found |
+----+--------------------+-----------------------+--------+---------------+----
--+---------+------+------+---------------------+
2 rows in set (0.00 sec)
mysql> explain SELECT * FROM openorders_tracking LEFT JOIN openorders_commission
ON openorders_tracking.id=openorders_commission.tracking_id WHERE openorders_co
mmission.id IS NULL;
+----+-------------+-----------------------+--------+---------------+------+----
-----+------+------+---------------------+
| id | select_type | table | type | possible_keys | key | key
_len | ref | rows | Extra |
+----+-------------+-----------------------+--------+---------------+------+----
-----+------+------+---------------------+
| 1 | SIMPLE | openorders_commission | system | PRIMARY | NULL | NUL
L | NULL | 0 | const row not found |
| 1 | SIMPLE | openorders_tracking | ALL | NULL | NULL | NUL
L | NULL | 341 | |
+----+-------------+-----------------------+--------+---------------+------+----
-----+------+------+---------------------+
2 rows in set (0.00 sec)