具有多个"OR"语句的MySQL查询 [英] MySQL query with multiple 'OR' statements

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

问题描述

我有一个查询,我已经在PHP之外直接在SQL上进行了测试,但仍然遇到相同的问题

I have a query, that I have tested outside of PHP directly on SQL and still getting the same problem

想法是$ currentArtist是使用GET方法发送的,该值与显示信息的event_artist列中的值匹配.

The idea being that $currentArtist is sent through using the GET method, where this value matches the value in the event_artist columns the information is displayed.

SELECT 
            *
        FROM
            `".DBN."`.`events`
        WHERE
            `event_artist1` OR `event_artist2` OR `event_artist3` = '".$currentArtist."'

    ";

我遇到的问题是它完全忽略了查询的WHERE部分.它仅返回完整的表结果,而不返回与$currentArtist匹配的结果.

The problem I have is that it is completely ignoring the WHERE part of the query. It just returns the complete table results and not the results that match $currentArtist.

我已经测试过$currentArtist,并且工作正常.我不知道如何使完整的陈述生效.

I have tested $currentArtist and it works fine. I'm at a loss as to how to get the complete statement to work.

我尝试将OR语句放在方括号中,如下所示:

I've tried surrounding the OR statements in brackets as in:

(`event_artist1` OR `event_artist2`...) = '".$currentArtist."'

仅当$currentArtist等于"1"(即存储艺术家信息的艺术家表中的第一个人)时,才会返回结果.

This only returns a result if the $currentArtist is equal to "1" being the first person in the Artists table where their information is stored.

任何帮助将不胜感激.

推荐答案

SELECT *
  FROM events e
 WHERE '$currentArtist' IN (e.event_artist1,e.event_artist2,e.event_artist3);

这篇关于具有多个"OR"语句的MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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