Interview question summary: SQL: where 1 = 1

1 = 1 is eternally established, meaning unconditional, that is to say, whether there is 1 = 1 in the SQL statement.

This 1 = 1 is often used by applications to piece together where conditions based on user selections .

For example, a simple query statement, where default is 1 = 1, so that even if the user does not select any conditions, the SQL query will not go wrong. If the corresponding parameters are passed in, then where becomes where 1 = 1 and column name = 'corresponding parameter'. If other conditions are also selected, it is enough to add the and statement after the where condition.

If you do n’t use 1 = 1, every time you add a condition, you need to determine whether there is a where condition in front. If you do n’t, you can write where ..., and write an and statement. degree.

 

Published 162 original articles · won 30 · 90,000 views +

Guess you like

Origin blog.csdn.net/ScorpC/article/details/102859497