Question: I have the following tables:

```
Contacts
      contact_id, contact_name, etc.
assigned_lists
      contact_id, list_id

```

Each contact can be associated with more than 1 list, which is stored in the `assigned_lists` column. 

I have a lot of contacts who are not associated with any lists. How would I insert all the `contact_id`'s that are not associated with a list into `assigned_lists`?

Answer: 
Try with:

```
INSERT INTO assigned_lists (contact_id, list_id)
SELECT contact_id, 24
FROM Contacts
WHERE contact_id NOT IN (
  SELECT DISTINCT contact_id
  FROM assigned_lists
)

```
you can try the below 

```
INSERT INTO assigned_lists (contact_id, list_id)
SELECT contact_id, list_id = 1234
FROM Contacts C
WHERE NOT EXISTS (SELECT 1 FROM assigned_lists A WHERE A.contact_id  = C.contact_id )

```

remember, not exists clause has a performance edge over not in clause. 

A detailed explanation about the same can be found here [NOT IN vs NOT EXISTS](https://stackoverflow.com/questions/173041/not-in-vs-not-exists)