Select all except the first character in a string in MySQL?

MySQLMySQLi Database

To select all except the first character in a string, you can use SUBSTR() method. Let us first create a table −

mysql> create table DemoTable
(
   FirstName varchar(20)
);
Query OK, 0 rows affected (0.63 sec)

Insert records in the table using insert command −

mysql> insert into DemoTable values('Larry');
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable values('Carol');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Robert');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('David');
Query OK, 1 row affected (0.14 sec)

Display records from the table using select command −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+
| FirstName |
+-----------+
| Larry     |
| Carol     |
| Robert    |
| David     |
+-----------+
4 rows in set (0.00 sec)

Here is the query to select all except the first character in a string −

mysql> select substr(FirstName,2) from DemoTable;

This will produce the following output −

+---------------------+
| substr(FirstName,2) |
+---------------------+
| arry                |
| arol                |
| obert               |
| avid                |
+---------------------+
4 rows in set (0.00 sec)
raja
Published on 30-Apr-2019 06:37:21
Advertisements