0

I am using MySQL, I have a table mtn_extract_list_email where there are columns called company,office,email,country and rating

I dont want emails that have domains aol , gmail, google

the query I am using is

select email from mtn_extract_list_email where (company like '%XYZ%' or office like '%XYZ%')
and (email not like '%@aol%' or email not like '%@gmail%' or email not like '%@google%')
and (Country = 'USA' and rating like 'A%')  
and email is not null;

this query fetches data but i noticed that it also fetched one email with @gmail as domain. I tried adjusting "AND" and "or" logic but still no luck. please guide what is wrong with my query.

3
  • 1
    Please edit your question title to something that describes the actual problem you're having. Query not working How'd I like will have absolutely no meaning if it turns up in a search result for a future user of this site. Your title should actually be descriptive; it's clear your query isn't working as you'd like, or you wouldn't be posting a question here. Commented Feb 5, 2015 at 23:18
  • 1
    You don't want domains in aol, AND you don't want gmail, AND you don't wan't google. The problem is that your query uses OR. Commented Feb 5, 2015 at 23:19
  • (email not like '%@aol%' AND email not like '%@gmail%' AND email not like '%@google%') Commented Feb 5, 2015 at 23:20

1 Answer 1

1

You are using or instead of and.

select email from mtn_extract_list_email 
        where (company like '%XYZ%' or office like '%XYZ%')
        (email not like '%@aol%' AND email not like '%@gmail%' AND email not like '%@google%')
        and (Country = 'USA' and rating like 'A%')  
        and email is not null;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.