简体   繁体   中英

ignoring condition in where clause in mysql

Can we write conditional where clause in mysql? I know one way ie with CASE WHEN

But my condition is if where clause fails then ignore it and execute query as there was no where clause

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

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

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