Home > Mobile >  MySQL: Alternative to using 'NOT'
MySQL: Alternative to using 'NOT'

Time:10-27

How do I rewrite this code so it returns the same, but without using 'NOT' notation?

SELECT * FROM mytable
WHERE col1 = 1
AND NOT ( col1 = col2 OR col3 = 3);

From what I can understand, this should be possible to do with a join function but I wasn't able to make it work.

CodePudding user response:

Dissipating NOT operator onto equalities(=) and OR operator, you can rewrite the statement as

SELECT * 
  FROM mytable
 WHERE col1 = 1
   AND col1 != col2 
   AND col3 != 3
  • Related