如何在下面的select语句中获得正确的结果
SELECT * FROM ads
WHERE ad_status='1'
AND ad_region='Location One' OR ad_region='Location Two' OR ad_region='Location Three'
AND ad_type='For Rent'
ORDER BY ad_id
DESC LIMIT 10
Run Code Online (Sandbox Code Playgroud)
本声明将返回所有ad_type(For Rent,Wanted,For Sale等),但我For Rent只想要.
我认为问题是ad_region因为有OR.如果没有"OR"(单个位置),结果是正确的.
让我知道.
您需要将OR条件放入括号或使用IN:
SELECT * FROM ads
WHERE
ad_status='1'
AND
ad_region IN ('Location One', 'Location Two', 'Location Three')
AND
ad_type='For Rent'
ORDER BY ad_id
DESC LIMIT 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |