Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a table like: enter image description here

which I am joining to another table: enter image description here

I want to get an output table that looks like this: enter image description here

I have discovered that my version of Netezza doesn't support concat but supports || instead. I have tried joining the table using the LIKE operator as follows:

SELECT A.*, CASE WHEN A.GENERIC_NAME LIKE ('%'||B.O_DRUGS||'%') THEN B.DRUG_CLASS ELSE NULL END AS OTHER_DRUGS FROM DRUG1 AS A LEFT JOIN DRUG_LIST AS B ON A.GENERIC_NAME LIKE ('%'||O_DRUGS||'%');

The code works for exact matches but the fuzzy matching is still not working. Clearly, I'm not using the like operator correctly for this purpose. Any suggestions??

question from:https://stackoverflow.com/questions/66055466/joining-using-like-operator-in-neteeza

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
85 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your LIKE conditions looks backwards:

FROM DRUG1 D1 LEFT JOIN
     DRUG_LIST DL
      ON DL.O_DRUGS LIKE '%' || D1.GENERIC_NAME || '%'

Note: Table aliases such as a are generally meaningless. Use abbreviations of the table names.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...