SQL NOT LIKE not functioning properly

时间:2018-04-18 17:47:59

标签: mysql sql navicat

I am unable to figure out why the NOT LIKE operators are not working properly. I have 34 sample_name in the database that start with NT but it only get rid of some, and not other. When I try searching with LIKE ('NT%), it search them all. Below is what I have.

WHERE
    full.full_id IN ('272', '273')
OR  full.full_id IN ('567', '686')
AND random.sample_name NOT LIKE ('NT%')

2 个答案:

答案 0 :(得分:2)

You have an extraneous , in the IN list and you are missing the ' at the end of your NOT LIKE statement. The statement should look like the following:

WHERE full.full_id IN ('272', '273', '567', '686')
AND random.sample_name NOT LIKE ('NT%')

答案 1 :(得分:1)

You have several errors in the code you have posted. I am going to guess that you intend:

WHERE full.full_id IN (272, 273) AND
      random.sample_name NOT LIKE 'NT%'

Notes:

  • No comma in the IN list.
  • Terminating single quote on LIKE pattern
  • Don't use single quotes for constants, if the column is a number (use single quotes only for string and date constants).
  • No parentheses are needed around the LIKE pattern (although that is not a syntax issue)