开发者

LIKE and filtering of records with MySQL does no change

I have my SQL, but the WHERE clause is what i'm having a problem with, since filtering out records with operators doesn't seem to filter the records, but picks up records when they shouldn't be, I need this LIKE/REGEXP to pick up records then narrow it down by including records that is true to the = statements.

WHERE  rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united'  
AND rec.ad_type = 1  
AND ( rec.num_rooms >= 15 AND rec.num_rooms IS NOT NULL )  
AND rec.visible_listing = 1

Nor this WHERE clause does filter out records:

WHERE  rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united' 
AND ( rec.ad_type = 1  AND ( rec.num_rooms >= 15 AND rec.num_rooms IS NOT NULL)  AND rec.v开发者_运维问答isible_listing = 1 ) 

Even changing rec.num_rooms / rec.ad_type to any number still doesn't change anything. Why is this?


Add parens around the ORs

WHERE  (rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united' )

AND rec.ad_type = 1  
AND rec.num_rooms >= 15 
AND rec.num_rooms IS NOT NULL 
AND rec.visible_listing = 1
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜