I am sure this really is straight-forward, but how do you write a question in mysql that joins two tables after which returns only individuals records in the first table that do not match. I would like it to be something similar to:

Select tid from table1 inner join table2 on table2.tid = table1.tid where table1.tid != table2.tid;

but this does not appear to create a lot of sense!

Use a [cde] to do this:

left outer join

What this may could it be takes the first table (select t1.tid from table1 t1 left outer join table2 t2 on t1.tid = t2.tid where t2.tid is null ), joins it together with your second table (table1), and fills in table2 for that null posts in almost any row in table2 that does not match a row in table1. Then, it filters that out by choosing just the table2 rows where no match might be found.

Alternatively, you may also use [cde]:


This works a not exists, and can basically perform the same factor the select t1.tid from table1 t1 where not exists (select 1 from table2 t2 where t2.tid = t1.tid) does. Based on your indexes, one might be faster compared to other, but both of them are viable options. MySQL has good quality documentation on optimizing the joins, so you can examine that out..