
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Select All Except the First Character in a String in MySQL
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)
Advertisements