
- 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 split a column after specific characters?
To split a column after specific characters, use the SUBSTRING_INDEX() method −
select substring_index(yourColumnName,'-',-1) AS anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable -> ( -> StreetName text -> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Paris Hill St.-CA-83745646') ; Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('502 South Armstrong Street-9948443'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------------------------------+ | StreetName | +------------------------------------+ | Paris Hill St.-CA-83745646 | | 502 South Armstrong Street-9948443 | +------------------------------------+ 2 rows in set (0.00 sec)
Following is the query to split a column after specific characters −
mysql> select substring_index(StreetName,'-',-1) AS Split from DemoTable;
Output
This will produce the following output −
+----------+ | Split | +----------+ | 83745646 | | 9948443 | +----------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to select a specific string with special characters
- MySQL query to count rows with a specific column?
- MySQL query to get all characters before a specific character hyphen
- MySQL query to remove special characters from column values?
- MySQL query to replace special characters from column value
- Adding new column after a specific column and defining a default in MySQL?
- MySQL Query to remove all characters after last comma in string?
- MySQL query to search within the last 5 characters in a column?
- Split a column after hyphen in MySQL and display the remaining value?
- How to select all the characters after the first 20 characters from a column in MySQL?
- How to get a specific column record from SELECT query in MySQL?
- MySQL query to retrieve only the column values with special characters?
- How to split a column in MySQL?
- MySQL query that returns a specific string if column is null?
- MySQL query to conduct a basic search for a specific last name in a column

Advertisements