Why we mention in MySQL WHERE 1=0?
Answers
Tutorialspoint
Search your favorite tutorials...
Why we mention in MySQL WHERE 1=0?
MySQLMySQLi Database
Follow Answer 8
1 Answer
George John
George John
Answered on 25th Feb, 2019
The condition 1=0 can be used to stop the query from returning any rows. It returns empty set.
The syntax is as follows:
SELECT *FROM yourTableName WHERE 1=0;
To understand the above syntax,let us create a table. The query to create a table is as follows:
mysql> create table ConditionDemo
-> (
-> Id int NOT NULL AUTO_INCREMENT,
-> Name varchar(10),
-> PRIMARY KEY(Id)
-> );
Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command. The query is as follows:
mysql> insert into ConditionDemo(Name) values('Larry');
Query OK, 1 row affected (0.10 sec)
mysql> insert into ConditionDemo(Name) values('Sam');
Query OK, 1 row affected (0.14 sec)
mysql> insert into ConditionDemo(Name) values('Mike');
Query OK, 1 row affected (0.13 sec)
mysql> insert into ConditionDemo(Name) values('Carol');
Query OK, 1 row affected (0.12 sec)
mysql> insert into ConditionDemo(Name) values('John');
Query OK, 1 row affected (0.17 sec)
mysql> insert into ConditionDemo(Name) values('Bob');
Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement.