What is the difference between NOT (x> y) and (x <y) in an SQL query?

What is the difference between the following query:

SELECT * FROM employee  WHERE NOT(start_date > '01-JAN-1970');

and this request:

SELECT * FROM employee  WHERE start_date < '01-JAN-1970';

Is there a difference, and if so, how NOT(x > y)is it used differently than (x < y). Can anyone provide an example?

Thanks.

+3
source share
9 answers

In MySQLandPostgreSQL

SELECT * FROM employee WHERE not(start_date > '01-JAN-1970')

will not use INDEXon start_date, if any, their optimizers are not smart enough.

Otherwise, if you correct a condition that is not necessarily strict in one of the cases (either not(start_date >= '01-JAN-1970'), or start_date <= '01-JAN-1970'), the queries are equal.

+8
source

Non-NOT equivalent

SELECT * FROM employee WHERE not(start_date > '01-JAN-1970');

is an

SELECT * FROM employee WHERE start_date <= '01-JAN-1970';

not

SELECT * FROM employee WHERE start_date < '01-JAN-1970';

as this will skip the case where start_date = '01 -JAN-1970 '

+5

not(start_date > '01-JAN-1970') 1 1970 ., start_date < '01-JAN-1970' , , .

+2

NOT() - , . :

SELECT * FROM employee WHERE not(start_date > '01-JAN-1970');

, 1970 . , < > , , .

+2

, , , < >= ( <= >), < >.

NOT , . :

SELECT * FROM my_table
WHERE my_column NOT IN (273, 430, 9567, 8, 433, 765, 6252, 13)

SELECT * FROM my_table
WHERE my_column NOT IN (SELECT another_column FROM another_table)

NOT .

+2

SQL- , , < = (, > < =), (x > y) ! (x < y) .

, " Y?". : "Y ";

! (x < y) == (x >= y)

+2

not start_date > '01 -JAN-1970 ', '01 -JAN-1970' start_date < '01 -JAN-1970 ', '01 -JAN-1970'

+1

, start_date == '01 -JAN-1970 '; -)

SELECT * FROM employee WHERE start_date <= '01-JAN-1970';
+1

( ), NOT , "start_date" - NULL, , , MySQL .

. /Darwen SQL . Null (. . 240, 241 ).

, , , , , , . , .

0

Source: https://habr.com/ru/post/1703486/


All Articles