mysql - Using "not in" on WHERE with AND? -
i'm trying better understanding of how "not in" works in mysql.
for example:
select * current_mailing_list address1 not in (select address1 old_mailing_list) , city not in (select city old_mailing_list); in above example, purpose of query list mailing addresses new. address1 street address such 1234 n. main st. problem happens when 1234 n. main st occurs in more 1 city, can happen. decided add city make more unique.
my question is, doing expect do? meaning, should find street addresses (address1) don't exist in old_mailing_list and make sure have different city.
i have done this, address1:
select * current_mailing_list address1 not in (select address1 old_mailing_list); and produced larger list (about 10 times size). wanted add city this. or logic in entirely wrong , need approach?
to use not in, you'll want combine both city , address in same clause mysql supports (other rdbms not support method). others have pointed out, won't desired results using both separately.
try if want use not in:
select * current_mailing_list (address1,city) not in (select address1, city old_mailing_list); i prefer use left join though , check null:
select c.* current_mailing_list c left join old_mailing_list o on c.address1 = o.address1 , c.city = o.city o.address1 null
Comments
Post a Comment