Table definitions and contents
CREATE TABLEER
(`id`int,`age`int)
;
INSERT INTER
(`id`,`age`)
VALUES
(1, 1),
(2, 2),
(3, 5),
(4, 7),
(5, 9)
;
Results you want to extract
did is not 3 < or 」age is not 2 では record
1,1
4,7
5,9
SQL1Tried
The result was unintended.
What does the following mean?
SELECT* FROM`r`WHERE`id`!=3 OR`age`!=2;
SQL2Tried
I was able to get the intended result (even though it's AND). Why?
Is this the logical sum of negatives?
SELECT* FROM`r`WHERE`id`!=3AND`age`!=2;
SQL1 is the negative OR (NOR) and SQL2 is the negative OR (NAND).
I think it's easy to understand if you think about it as a reverse event.
SQL1 is the inverse of id=3ANDage=2(A BB), so id!=3ORage!=2(notA nnotB).
In other words, it's the opposite of the combination of (3,2), so I'll select something other than the combination of (3,2).
SQL2 is the inverse of id=3orage=2(A BB), so id!=3ANDage!=2(notA nnotB).
If id=3 or age=2 is selected (2,2)(3,5) and it is the opposite, so the rest will be returned.
Also, it may be easy to draw a Ben diagram of A and B and A or B, and vice versa.
© 2024 OneMinuteCode. All rights reserved.