Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: open

Message Too Old, No Replies

MySQL - 3 columns with same data type in different tables

Avoiding duplicate results

     

Readie

2:45 pm on May 3, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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? :)

Thanks in advance,

Readie

LifeinAsia

3:48 pm on May 3, 2011 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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.

Readie

8:44 am on May 4, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



This works perfectly, thanks very much :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month