简体   繁体   中英

Mysql query syntax for multiple conditions in select

Hello everyone I am having trouble with mysql query select syntax

WHERE ((a.product_id = b.product_id) AND (b.category_id = '20') AND (a.product_publish = '1') AND ( a.product_manufacturer_id = 2 ) AND (a.extra_field_10 = 92 ) AND (a.product_price BETWEEN 171 AND 631 ))

do you see any problem here?? (maybe missing quotes)

category_id (integer)
product_publish (integer)
extra_field_10  (integer)
product_price (integer)
manu (integer)

if you ask why are there brackets they are here because of multiple conditions like

WHERE ((a.product_id = b.product_id) AND (b.category_id = '20' || b.category_id = '21') AND (a.product_publish = '1') AND ( a.product_manufacturer_id = 2 ) AND (a.extra_field_10 = 92 || a.extra_field_10 = 11 ) AND (a.product_price BETWEEN 171 AND 631 ))

SELECT is correct FROM is correct too values are correct it has to be syntax problem which i am missing

UPDATED * ** * ***

  • there are no errors sql just return false
  • i know brackters are not neccesary but also they dont make errors
  • columns are ok i am using similar selects and they work ok but this one cant work right

UPDATED * ** * ** * ** * ** * ***

looks like there has to be problem somwhere else i will update this post when i figure out real problem maybe it could help someone in the future

You do not need so many parenthesis in your code. It would be interesting also you post your table in http://sqlfiddle.com/ .
I believe this query (if all the fields in your query exist) will work.
ps: If a field is integer you do not need quotes provided.

WHERE a.product_id = b.product_id AND b.category_id = 20 AND a.product_publish = 1
AND product_manufacturer_id = 2  AND a.extra_field_10 = 92 AND a.product_price BETWEEN 171 AND 631

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM