|
Hi Expert, There 2 tables emailinfo(id,email) and keywordinfo(id,keyword). emailinfo contains 80,000 rows and keywordinfo contains 2000 rows. I want emails from emailinfo table which does not contains keywords from keywordinfo table. eg. SELECT email FROM emailinfo WHERE email not like '%yahoo%' AND email not like '%gmail%' but this is hardcoded example.and i kept these keywords in keywordinfo table. In sql procedure i tried for following query, SELECT EMAIL.email FROM emailinfo EMAIL WHERE ( not exists( Select keyword from keywordinfo where EMAIL.email like '%'+ keyword +'%' )) which take 2 minutes to execute. I want query like following SELECT EMAIL.email FROM emailinfo EMAIL where EMAIL.email not like '%' ( SELECT keyword from keywordinfo ) '%' i know above subquery returns multple rows,but i want something like that. i have googled many examples but they failed to satisfying my problem Please help me to write NOT LIKE subquery with values pulled from another table? Thanks in advance.
(comments are locked)
|
|
I can understand what is desired. You need to know any new keywords missing in your keyword table. But I guess this should be done at the time of insert/update if to be handled efficiently. Otherwise, should be done as a nightly job. How about Extract the keyword by finding the string between @ and first . DECLARE @email VARCHAR(50) A very good article by Aaron Bertrand is here http://www.mssqltips.com/sqlservertip/2657/storing-email-addresses-more-efficiently-in-sql-server/ EDIT..... I have simulated the exact case on my machine but without the use of NOT LIKE and it worked great
(comments are locked)
|


Better would have been a breakdown of the email column into actual email, keyword like "google . com". That way this query could have been handled efficiently.
Thanks for replying me. In my software there are 2 options during fetching emails 1 skip the email containig keywords 2 dont skip email containing keywords.