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.
I want not like condition on multiple rows
I have kept all keywords in keywordinfo table
Now I have to fetch all the emails from emailinfo table which not containing any keywords from keywordinfo table.
I want query like following,
select email
from emailinfo
where email not like % (select keyword from keywordinfo)
I have tried following query
SELECT email
FROM emailinfo
join keywordinfo on email like '%' + keyword +'%'**
but its not giving me proper results and is very slow.
Instead of trying to come up with a scenario using LIKE, have you considered using FULL TEXT INDEXING?
Pinal Dave has a fairly good introduction on it that can help get you started: http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/
An alternative formulation eliminates the like:
I apologize for the formatting, I'm on a mobile device.
I would also recommend that you change your table structures so each keyword is in a separate row. Then you won't need the like operator.
How about a slight variation of your second query...?
Example Data:
The following query will returns all the records from emailinfo table which don't have any keyword defined in keywordinfo table.
It's advisable to have an index on emailinfo.email fields to make the query execution faster.