An incomplete site has recently come to me to complete development on, and I'm having a bit of an issue with this one.
This site stores Email addresses in 3 different database tables depending on how the user registered.
If the user registered via Facebook, the user's Email address is stored under `email` in `ph_user`.
If the user registered through the site as a normal user, the user's email is stored under `username` in `ph_standard_auth`.
If the user registered through the site as a business owner, the email is stored under `email` in `ph_listing`.
A single address could appear in 1 or 2 (not all 3) of these tables at the same time.
My client has asked me to generate a CSV file from these 3 tables containing the email, first name and last name of every user, with the email address being unique.
There are currently just under 2 million rows available between these 3 tables, and it is only going to increase, so I cannot do a dirty hack of a sub-query to check the existence in a table I have already retrieved the data from, and I cannot have a "where not in()" generated through a PHP array either. It would just be too slow.
So, if anyone here has ever had an issue of this sort arise before, could you please share any information you have that might help? :)
UNION should work for you. However, if there are any instances of where the first and last names do not match exactly between the tables (maybe the business owner added his middle initial to one of them), you'll get multiple instances of the e-mail address.