CREATEtableWhereConditon->(->idint,->namevarchar(100)->);QueryOK,0rowsaffected(0.43sec) After successfully creating the table, insert some records through the insert command. The query for this is as follows -mysql> INSERTintoWhereC"/> CREATEtableWhereConditon->(->idint,->namevarchar(100)->);QueryOK,0rowsaffected(0.43sec) After successfully creating the table, insert some records through the insert command. The query for this is as follows -mysql> INSERTintoWhereC">
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)
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)
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;
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)
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;
The following is the output of the above query
+-------+ | name | +-------+ | John | | Smith | | Bob | | David | +-------+ 4 rows in set (0.00 sec)
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!