How to understand the logic operation of this query statement-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.