I want to get row count in tableA if and only if rowA_x does not have a FK pointing to rowB_x in tableB.
tableA:
id | id_tableB
tableB
id | ...
So basically the rows in tableA should only be counted if the column id_tableA does not exist as id in tableB.
Is there a clean way to do such counting. I have around ~500.000 rows.
There are several (not 100% sure about the MySQL syntax, so this might require some tweaking):
Subselect with NOT IN:
Subselect with NOT EXISTS:
OUTER JOIN:
Which of these is the fastest depends on your data, but usually, a JOIN is more efficient than a subquery.