2017-08-31 20 views
0

列またはgeneric列のいずれかに、citalopramという語またはcelexaという語を含む行を取得しようとするクエリがあります。where節がPostgresクエリで適切な行を選択しない

まず私が試した:

where  
    ( medication  ilike '%citalopram%' or 
     generic  ilike '%citalopram%' or 
     medication  ilike '%celexa%'  or 
     generic  ilike '%celexa%') 

そしてそれはまた、薬物escitalopramを含まれる行を選択し、以外のすべてが、見つけるとダンディだったが。今

where  
    ( medication  ilike '%citalopram%' or 
     generic  ilike '%citalopram%' or 
     medication  ilike '%celexa%'  or 
     generic  ilike '%celexa%')   and 
     medication not ilike '%escitalopram%' and 
     generic not ilike '%escitalopram%' 

案の定、それはescitalopramを含む行を排除し、今は時々持って行無視し、::

  • 薬= CeleXa 40mg oral tablet、ジェネリックをそれは次のように見えたように、だから私は、クエリを変更しました= null
  • 薬= citalopram 40mg oral tablet、ジェネリック= null

など

これがなぜ問題なのかわかりません。任意の提案をいただければ幸いです!

+2

を持っているでしょう単語から始まるので、もし

where concat(' ',medication,' ',generic) ilike '% citalopram%' or concat(' ',medication,' ',generic) ilike '% celexa%' 

が列の前にスペースを入れて - このHTTPSを読む価値を: //stackoverflow.com/questions/22818070/behaviour-of-not-like-with-null-values –

+0

正規表現を使用して「単語全体」検索を行う方がよい場合があります。 '投薬〜* '\ ycelexa \ y'' –

答えて

0

なぜ:列の値が、それはまだそれがあるため、汎用のNULL値持っているスペース

関連する問題