Find specific records which has whitespace on the second place in MySQL


For this, use SUBSTR() as in the below syntax −

select * from yourTableName
where substr(yourColumnName, 2, 1 ) = ' ';

Let us first create a table −

mysql> create table DemoTable1365
    -> (
    -> Value varchar(20)
    -> );
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1365 values('9756757474');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1365 values('3 45322333');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable1365 values('8974646363');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1365 values('9 566363622');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1365;

This will produce the following output −

+-------------+
| Value       |
+-------------+
| 9756757474  |
| 3 45322333  |
| 8974646363  |
| 9 566363622 |
+-------------+
4 rows in set (0.00 sec)

Here is the query to find the specific records in the table which has white space only on the second place like “3 4532” −

mysql> select * from DemoTable1365
    -> where substr(Value, 2, 1 ) = ' ';

This will produce the following output −

+-------------+
| Value       |
+-------------+
| 3 45322333  |
| 9 566363622 |
+-------------+
2 rows in set (0.00 sec)

Updated on: 08-Nov-2019

483 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements