How should we understand the logic operation of this query statement? SELECT & nbsp; abcd & nbsp; FROM & nbsp; 'goods' & nbsp; AS & nbsp; g & nbsp; WHERE & nbsp; is_delete & nbsp; 0 & nbsp; AND & nbsp; is_alone_sale & nbsp; what is the logical operation of this query statement?
SELECT abcd FROM 'goods' AS g WHERE is_delete = 0 AND is_alone_sale = 1 AND (1 AND cat_id IN ('8 ','') AND (0 OR goods_name LIKE '% advanced commerce %' OR goods_sn LIKE '% advanced commerce %' OR keywords LIKE '% advanced commerce %') OR goods_id IN ('') order by goods_id DESC
The preceding query statement runs correctly. now I remove AND (1 in 1, so that the following SQL statement is printed:
SELECT abcd FROM 'goods' AS g WHERE is_delete = 0 AND is_alone_sale = 1 AND (AND cat_id IN ('8 ','') AND (0 OR goods_name LIKE '% advanced commerce %' OR goods_sn LIKE '% advanced commerce %' OR keywords LIKE '% advanced commerce %') OR goods_id IN ('') order by goods_id DESC
See AND (here, there is 1 less than the original one, but an error occurs. the prompt is as follows:
Fatal error: Call to a member function on a non-object in search. php on line 278
I cannot figure out whether the 1 operation is invalid. is 1 the result value of is_delete = 0 AND is_alone_sale = 1? If my understanding is incorrect, please correct it.
Also, AND (0 here, where is the result value of 0? If not, what does that mean?
The above is about logical operations. I have read the manual for a long time and still cannot understand it. please feel free to ask for your help. thank you.
------ Solution --------------------
Of course, there are brackets!
Inside the brackets is a whole
AND cat_id IN ('8 ','') AND (0 OR goods_name LIKE '% advanced commerce %' OR goods_sn LIKE '% advanced commerce %' OR keywords LIKE '% advanced commerce % ')
Is such a statement correct?
Maybe the SQL parser thinks that the AND at the beginning is a function, so there is such an error. 1 is indispensable!
------ Solution --------------------
...
You don't know that the logical expression is a and B .....
If you write a and B as and B, it will certainly be wrong...
You just need to remove the and behind 1...
Dizzy...
1 and .... This is just for the convenience of SQL statement combination.
Given 1 (true) at the beginning of and, then we can continually add conditions for and a1 and a2... Form generation.
The landlord should look for any programming language book and review the basic knowledge...