sql - How to reuse query of IN sub query? -


i have below query

select a.id, a.user_id, a.approver_id, a.second_approver_id  tbl_approve_master  user_id in (select id tbl_user name '%john%') or approver_id in (select id tbl_user name '%john%')  or second_approver_id in (select id tbl_user name '%john%')  

how reuse query statement of in ? tried accept answer of how reuse sub query in sql? as

with cte (select id tbl_user name '%john%') select a.id, a.user_id, a.approver_id, a.second_approver_id  tbl_approve_master  user_id in cte or approver_id in cte  or second_approver_id in cte 

but not ok. how can achieve ?

try this:

select a.id, a.user_id, a.approver_id, a.second_approver_id  tbl_approve_master  exists (     select *      tbl_user u     u.name '%john%'     , u.id in (a.user_id, a.approver_id, a.second_approver_id) ) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -