In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail why where 1 is used in mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
This condition is always True. In the case of an indefinite number of query conditions, where 1 can be a convenient specification statement. 1 answer 1 is always valid, meaning unconditional, that is to say, it doesn't matter whether there is such a 1Q 1 in the SQL statement.
For example, the web interface queries the user's information, and where defaults to 1: 1, so that even if the user does not select any conditions, the sql query will not make an error. If the user chooses a name, then where becomes where 1 name 1 and name = 'name entered by the user', and if other conditions are selected, just keep appending and statements to the where condition.
If you don't need 1x1, you have to determine whether there is a where condition or not. If not, write where..., and write and statements, so using 1q1 at this time can simplify the complexity of the application.
For example, for an indefinite number of query conditions, when we write a query in the background, the statement string sql = "select * from table where" is similar to this.
If (starttimekeeper null) {
Sql = sql+ "starttime=" + starttime
}
If (endtime! = null) {
Sql = sql+ "and endtime =" + endtime
}
At this time, our query statement is select * from table where starttime = 2015-04-05 and endtime = 2015-04-07. The query statement is correct.
However, if the conditions are not met, the statement becomes select * from table where, and the query will report an error.
When you add 1 to 1,
String sql = "select * from table where 1 # 1"
If (starttimekeeper null) {
Sql = sql+ "and starttime=" + starttime
}
If (endtime! = null) {
Sql = sql+ "and endtime =" + endtime
}
When the two conditions are true, select * from table where 1 and starttime = 2015-04-05 and endtime = 2015-04-07, the statement is correct
When the two conditions are not met, select * from table where 1 will return all data of the table table if the statement is correct.
This is the end of the article on "Why to use where 1 in mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.