select - MySQL syntax for treating an inline CSV as a temporary table? -
temporary table may overkill i'm trying do. basically, want invert following mysql query:
select email email_newsletter_subscriptions unsubscribedate not null , email in ( # csv list of email address )
this query gives me list of email addresses exist in table , have unsubscribed. want list of emails in in csv don't exist in email_newsletter_subscriptions
or exist has null unsubscribedate
.
i found 1 crazy work around that's surprisingly snappy dataset (~1k rows), gets unwieldy create larger input sets.
select email (select 'john.doe@exmple.com' email union select 'jane.do@example.com' email) e left join email_newsletter_subscriptions ens using(email) ens.email null or ens.unsubscribedate null;
is there easier syntax can take input csv without having turn every line select ... union all
monstrosity?
i'm aware load these temporary table , lot more options, i'd have simple, single-query method copy-paste drop in works (i don't have temporary table permissions on target environment).
a temporary table correct solution here. can use load data local upload local client, , run query similar posted.
create temporary table local_list (email varchar(255) primary key ); load data local infile '/tmp/input.csv' table local_list; select email local_list left join email_newsletter_subscriptions ens using (email) (ens.email null) or (ens.unsubscribedate not null);
Comments
Post a Comment