
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to remove string from a column with values EMP1, EMP2, EMP3, etc.
To remove string from the values EMO1, EMP2, etc., you need to use RIGHT() along with LENGTH(). Let us first create a table −
mysql> create table DemoTable1540 -> ( -> EmployeeCode varchar(20) -> ); Query OK, 0 rows affected (0.39 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1540 values('EMP9'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1540 values('EMP4'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1540 values('EMP8'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1540 values('EMP6'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1540;
This will produce the following output −
+--------------+ | EmployeeCode | +--------------+ | EMP9 | | EMP4 | | EMP8 | | EMP6 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to remove string from column values −
mysql> select right(EmployeeCode,length(EmployeeCode)-3) as onlyDigit from DemoTable1540;
This will produce the following output −
+-----------+ | onlyDigit | +-----------+ | 9 | | 4 | | 8 | | 6 | +-----------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to remove special characters from column values?
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- MySQL query to update all the values in a column with numeric incremental values like John1, John2, John3, etc.
- MySQL query to separate and select string values (with hyphen) from one column to different columns
- MySQL query to get string from one column and find its position in another column with comma separated values?
- How to remove only the first word from columns values with a MySQL query?
- MySQL query to remove a value with only numbers in a column
- Fetch maximum value from a column with values as string numbers like Value440, Value345, etc. in SQL
- MySQL query to find the average of only first three values from a column with five values
- MySQL query to remove Null Records in a column?
- MySQL query to get first two highest column values from a table?
- A single MySQL query to search multiple words from different column values
- MySQL query to calculate the total amount from column values with Cost and Quantity?
- MySQL query to display record with maximum count values in a group with other column values?
- MySQL query to display only the column values with corresponding column having whitespace

Advertisements