A. Appleby A. Appleby - 3 months ago 14
MySQL Question

Cross reference table data in SQL

I've got a

bookings
and
contacts
table. I need to get all the email addresses that are found in the bookings table, but not in the contacts table. Is this possible in SQL?

There are like 160k rows for bookings, and 711k contacts so can't really be making arrays as it'll time out. Copy and pasting is also too difficult because of the size. Any suggestions for this?

Answer

I don't know what your table structure is like, but this may apply to you:

SELECT email 
FROM bookings a 
WHERE NOT EXISTS
(
    SELECT  email
    FROM    contacts b
    WHERE   a.email = b.email
)

This will select all the email addresses from the bookings table where that email is not found inside the contacts table.

Comments