Home > Database > Mysql Tutorial > What is the 'where 1=1' statement in MySQL?

What is the 'where 1=1' statement in MySQL?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-04 17:21:03
forward
1261 people have browsed it

MySQL 中的“where 1=1”语句是什么?

In MySQL, "Where 1=1" produces all rows in the table because the statement is always true. one To better understand the statement, the example is given below -

First, create a table with the help of create command. The following is given -

mysql> CREATE table WhereConditon
-> (
-> id int,
-> name varchar(100)
-> );
Query OK, 0 rows affected (0.43 sec)
Copy after login

After successfully creating the table, insert some records through the insert command The query for this is as follows -

mysql> INSERT into WhereConditon values(1,'John');
Query OK, 1 row affected (0.16 sec)

mysql> INSERT into WhereConditon values(2,'Smith');
Query OK, 1 row affected (0.15 sec)

mysql> INSERT into WhereConditon values(3,'Bob');
Query OK, 1 row affected (0.16 sec)

mysql> INSERT into WhereConditon values(4,'David');
Query OK, 1 row affected (0.13 sec)
Copy after login

Now the record is inserted successfully and you can see the number of records in the table Check with the help of select statement. Given below -

mysql> SELECT * from WhereConditon;
Copy after login

After executing the above query, you can see all the records in the table as follows -

+------+-------+
| id   | name  |
+------+-------+
| 1    | John  |
| 2    | Smith |
| 3    | Bob   |
| 4    | David |
+------+-------+
4 rows in set (0.00 sec)
Copy after login

Now, statement 1=1 is used with select statement to display table. All the names will be displayed as 1=1 is always true.

The query for this is as follows -

mysql> select name from WhereConditon where 1=1;
Copy after login

The following is the output of the above query

+-------+
| name  |
+-------+
| John  |
| Smith |
| Bob   |
| David |
+-------+
4 rows in set (0.00 sec)
Copy after login

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

Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template