Home  >  Article  >  Database  >  What does where 1=1 mean in SQL statement?

What does where 1=1 mean in SQL statement?

angryTom
angryTomOriginal
2020-02-13 17:19:587778browse

What does where 1=1 mean in SQL statement?

What does where 1=1 mean in the sql statement?

where 1=1 should be automatically generated by a program (such as Java). The conditions after 1=1 in the where condition are dynamically changed through the if block. For example:

String sql="select * from table_name where 1=1";
if( conditon 1) {
    sql=sql+" and var2=value2";
}
if(conditon 2) {
    sql=sql+" and var3=value3";
}

where 1=1 is to avoid grammatical errors caused by the first word after the where keyword being directly "and".

PHP Chinese website has a large number of free SQL tutorials, everyone is welcome to learn!

The above is the detailed content of What does where 1=1 mean in SQL statement?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn