开发者

NOT LIKE multiple OR statements?

if have a mailing script that i've set to throttle domains i send to. the remaining domains that do not have a throttle rate set, get assigned a default rate. to find domains which开发者_C百科 do NOT match an existing throttled domain, i use this php:

$query = "SELECT * FROM `mailer_lists` ml JOIN `mailer_controller` mc";
        $query .= " ON ml.project_name = mc.project_name";
        $query .= " WHERE `email` NOT LIKE '%";
        $query .= "" . implode("' OR '%", $throttle_domain) . "'";
        echo "$query";

the output of the echo is:

SELECT * FROM `mailer_lists` ml JOIN `mailer_controller` mc ON ml.project_name = mc.project_name WHERE `email` NOT LIKE '%gmail.com' OR '%hotmail.com' OR '%yahoo.com' OR '%aol.com'

as far as i can tell the output looks perfectly fine. i ran a test query in phpmyadmin and only the first domain applies. anything after the OR is ignored.

is there something obviously wrong with this query that i'm missing? can't you use multiple OR statements while using the NOT LIKE statement?


I would do

where substring_index(`email`,'@',-1) not in ('yahoo.com','gmail.com')

and so on.


You're taking mySQL's "human language" approach too far. :) Each OR is interpreted as an expression of its own, not as a value to do a LIKE against.

Also, I think you want to use AND. Using OR will always apply to every row.

Try

    (`email` NOT LIKE "%gmail.com") 
AND (`email` NOT LIKE "%hotmail.com") 
AND (`email` NOT LIKE "%yahoo.com") ....


You must repeat the field_name not like part :

SELECT * 
FROM `mailer_lists` ml 
    JOIN `mailer_controller` mc ON ml.project_name = mc.project_name 
WHERE 
    `email` NOT LIKE '%gmail.com' 
    and `email` NOT LIKE '%hotmail.com' 
    and `email` NOT LIKE '%yahoo.com' 
    and `email` NOT LIKE '%aol.com' 
LIMIT 50

(And you probably have to use and, instead of or, between the conditions)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜