简体   繁体   English

选择中多个条件的MySQL查询语法

[英]Mysql query syntax for multiple conditions in select

Hello everyone I am having trouble with mysql query select syntax 大家好,我在使用mysql查询选择语法时遇到麻烦

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 SELECT是正确的FROM也是正确的值也是正确的它必须是我缺少的语法问题

UPDATED * ** * *** 更新* ** * ***

  • there are no errors sql just return false sql没有错误,只是返回false
  • i know brackters are not neccesary but also they dont make errors 我知道bra子不是必需品,但他们也不会犯错
  • 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/ . 您也可以将表发布到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. ps:如果字段是整数,则不需要提供引号。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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