Excerpt from: http://blog.sina.com.cn/s/blog_afe616ab0101camd.html
The role of SQL where 1=1 and 0=1
where 1=1; This condition is always true, and in the case of an indefinite number of query conditions, the 1=1 can be a convenient specification statement.
For example, if you make a query page, let the user choose and enter the query keyword, the code is generally as follows:
String mysqlstr= "select * from table where";
if (age.text.lenght>0) {
mysqlstr=mysqlstr+ "age=" + "' age.text '";
}if (address.text.lenght>0) {
mysqlstr=mysqlstr+ "and address=" + "' address.text '";
}
If the above two if judgment statements do not hold, then the final mysqlstr dynamic construct statement becomes: mysqlstr= "select * from table where" the statement is an incorrect statement.
where 1=0; This condition is always false, and the result does not return any data, only the table structure, which can be used to quickly build the table "select * from strName WHERE 1 = 0"; This SELECT statement is primarily used to read the structure of a table without regard to the data in the table, saving memory because you can save the result set. CREATE TABLE newtable as SELECT * from oldtable where 1=0; Creates a new table, and the structure of the new table is the same as the structure of the queried table.
where 1=1 and 0=1 in SQL statements