A. Appleby A. Appleby - 1 year ago 82
MySQL Question

Cross reference table data in SQL

I've got a

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 Source

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

SELECT email 
FROM bookings a 
    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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download