如何使用多个或&和mysql中的条件

时间:2016-11-30 07:17:29

标签: mysql

我需要comp_gid作为强制性剩余字段,如holder1_name,holder1_fh_name,holder1_pan_no可能包含值或者它将为null

SELECT * 
FROM sta.sta_trn_tfolio 
where (holder1_name='AMAR' or holder1_fh_name='' or holder1_pan_no='') 
AND comp_gid='1' ;

但我只得到comp_gid条件。如果有人知道,请帮助我

1 个答案:

答案 0 :(得分:0)

您应该添加对NULL的检查:

 SELECT * FROM sta.sta_trn_tfolio 
 where 
    (holder1_name IS NULL OR 
     holder1_fh_name IS NULL OR 
     holder1_pan_no IS NULL OR 
     holder1_name='AMAR' or 
     holder1_fh_name='' or 
     holder1_pan_no='')     
    AND comp_gid='1' ;