简体   繁体   中英

Mysql priority condition with where clause

I try to check two conditions when checking first condition if it is true then ignore second condition. if first condition false then check second condition.

here query like this

select * from region_daten inner join werte_inc where datum = today or datum = yesterday"

桌子看起来像这样

here returns today and yesterday because both are true but before 11:30 am i have only yesterday date after 11:30 am i have both dates. when i do with 'or' i got both dates data. but i need to show if date is today date i have to display today date data. if not i have to display yesterday data.

Let's create a truth table:

date = today | date = yesterday | desired result
-------------+------------------+---------------
true         | true             | true
true         | false            | true
false        | true             | true
false        | false            | false

If this table is correct according to Your question, then what You are looking for is an OR:

SELECT *
FROM table 
WHERE date = today OR date = yesterday

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