在 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”语句是什么?的详细内容。