SQL查询多个AND和OR不起作用 [英] SQL Query multiple AND and OR's not working

查看:712
本文介绍了SQL查询多个AND和OR不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单元格,其中包含用双引号分隔的值.我正在尝试使用以下内容搜索此单元格的内容,(其中10是要搜索的数字)%10、10%,%10%和10

I have a cell that contains values separated by a double pipe. I am trying to search over the contents of this cell with the following, (where 10 is the number to search for) %10, 10%, %10% and 10

我的查询似乎只返回10.没有其他变化.有人可以告诉我为什么它不起作用吗?

My query only seems to be returning 10. none of the other variations. Can someone please advise me why it's not working?

非常感谢. (您在下面看到的SQL查询是从准备好的PDO查询语句中导出的内容)

Many thanks in advance. (the SQL query you see below is what is exported from a prepared PDO query statement)

SELECT  `Hat`.`id` AS  `Hat_id` ,  `Hat`.`hatCode` AS  `Hat_hatCode` ,  `Hat`.`hatCodeOther` AS  `Hat_hatCodeOther` ,  `Hat`.`name` AS  `Hat_name` ,  `Hat`.`description` AS  `Hat_description` , `Hat`.`colorId` AS  `Hat_colorId` ,  `Hat`.`collectionId` AS  `Hat_collectionId` ,  `Hat`.`mainPicture` AS  `Hat_mainPicture` ,  `Hat`.`subPicture` AS  `Hat_subPicture` ,  `Hat`.`type` AS  `Hat_type` , `Hat`.`featured` AS  `Hat_featured` ,  `Hat`.`published` AS  `Hat_published` ,  `Hat`.`deleted` AS  `Hat_deleted` 
FROM  `modx_hats` AS  `Hat` 
WHERE (
(
`Hat`.`published` =1
AND  `Hat`.`collectionId` =  '1'
)
AND  `Hat`.`colorId` =  '%||10||%'
OR  `Hat`.`colorId` =  '10||%'
OR  `Hat`.`colorId` =  '%||10'
OR  `Hat`.`colorId` =  '10'
)
LIMIT 0 , 30

推荐答案

我认为您应该使用LIKE而不是=:

I think that you should use LIKE instead of =:

AND  `Hat`.`colorId` LIKE '%||10||%'
OR  `Hat`.`colorId` LIKE '10||%'
OR  `Hat`.`colorId` LIKE '%||10'
OR  `Hat`.`colorId` =  '10'

这篇关于SQL查询多个AND和OR不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆