首页  >  文章  >  数据库  >  MySQL 中的“where 1=1”语句是什么?

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

WBOY
WBOY转载
2023-09-04 17:21:031147浏览

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

在 MySQL 中,“Where 1=1”会生成表中的所有行,因为该语句始终为真。一个 为了更好地理解该语句,给出的示例如下 -

首先,在 create 命令的帮助下创建一个表。给出如下 -

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

成功创建表后,通过insert命令插入一些记录 对此的查询如下 -

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)

现在记录插入成功,可以看到表中的记录条数 借助 select 语句进行检查。给出如下 -

mysql> SELECT * from WhereConditon;

执行上述查询后,可以看到表中的所有记录如下 -

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

现在,语句 1=1 与 select 语句一起使用,以显示 table. All the names will be displayed as 1=1 is always true.

对此的查询如下 -

mysql> select name from WhereConditon where 1=1;

以下是上述查询的输出

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

以上是MySQL 中的“where 1=1”语句是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除