Can 'false' match some string in MySQL?


Yes, you can use false as 0 to match.

Let us first create a table −

mysql> create table DemoTable804 (
   Id varchar(100)
);
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable804 values('101John');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable804 values('Carol1002');
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable804 values('1000');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable804 values('1010Bob');
Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable804;

This will produce the following output -

+-----------+
| Id        |
+-----------+
| 101John   |
| Carol1002 |
| 1000      |
| 1010Bob   |
+-----------+
4 rows in set (0.00 sec)

Here is the query for false match. If a string is found at first, then it won’t convert and 0 would be visible. The same occurred in row 2 as shown below −

mysql> select 0+Id from DemoTable804;

This will produce the following output -

+------+
| 0+Id |
+------+
| 101  |
| 0    |
| 1000 |
| 1010 |
+------+
4 rows in set, 2 warnings (0.00 sec)

Updated on: 09-Sep-2019

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements