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
精彩评论