Question: I have the following query:

```
select * from table_2 
where 
user_1 not in (select user_id from users) or 
user_2 not in (select user_id from users)

```

The problem is that it takes very long time to execute. The tables have few millions of records. Is there any optimization that I can use for the query?

Answer: 
You should try this:

```
select * from table_2
LEFT JOIN `users` AS u ON u.user_id = table_2.user_1
LEFT JOIN `users` AS u2 ON u2.user_id = table_2.user_2
WHERE u.user_id is NULL and u2.user_id is NULL

```
```
SELECT * FROM table_2 t2 
WHERE
NOT  EXISTS( SELECT 1 FROM users u WHERE  u.user_id IN(t2.user_1,t2.user_2) )

```

this should perform better.