简体   繁体   English

忽略mysql中where子句中的条件

[英]ignoring condition in where clause in mysql

Can we write conditional where clause in mysql? 我们可以在mysql中编写条件where子句吗? I know one way ie with CASE WHEN 我知道一种方式,即CASE WHEN

But my condition is if where clause fails then ignore it and execute query as there was no where clause 但我的条件是如果where子句失败然后忽略它并执行查询,因为没有where子句

eg. 例如。 I want to select persons in particular city. 我想选择特定城市的人。 but if I got city null as input then ignore that statement and return all persons in all cities 但如果我输入null作为输入,则忽略该语句并返回所有城市中的所有人

Can someone please tell me how to do this 有人可以告诉我如何做到这一点

please Help!! 请帮忙!!

像这样的东西?

select p from Person p where (:city is null or p.city = :city)
select * from your_table
where @city is null 
or city = @city

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

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