简体   繁体   中英

Mysql how to write a query contains where followed by condition

I am writing one query, that needs to satisfy the following conditions.

select 
    field1, field2, field3
from 
    `tabFirstTable`as ft join 
    `tabSecondTable` as st
where 
    --Upto above its fine but how to turn below logic into query-- 
    IF ft.approval_status in == 'Approved By Manager' and ft.status in ("Created", "Error")
        and //some more conditions
    ELSE ft.approval_status in == 'Approved By HOD' and ft.status in ("Initiated")
        and //some more conditions

Because of the above issue currently writing two separate queries, which is not a good idea. Please help.

Unless I am missing something or over simplifying

WHERE
    (ft.status IN ('Created', 'Error') AND 
    ft.approval_status = 'Approved By Manager' AND 
        //other stuff
    )
OR 
    (ft.status = 'Initiated' AND 
     ft.approval_status = 'Approved By HOD' AND 
        //some more conditions
    )

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