
- 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
Fetch the substring after last dot in MySQL
To fetch the substring after last dot, use substring_index(). Let us first create a table −
mysql> create table DemoTable1341 -> ( -> Value varchar(60) -> ); Query OK, 0 rows affected (0.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1341 values('John.123.@gmail.com' ); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1341 values('Carol.Taylor.gmail') ; Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1341 values('C.MyFolder.Location') ; Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1341;
This will produce the following output −
+---------------------+ | Value | +---------------------+ | John.123.@gmail.com | | Carol.Taylor.gmail | | C.MyFolder.Location | +---------------------+ 3 rows in set (0.00 sec)
Here is the query to fetch the substring after last dot −
mysql> select substring_index(Value, '.', -1) from DemoTable1341;
This will produce the following output −
+---------------------------------+ | substring_index(Value, '.', -1) | +---------------------------------+ | com | | gmail | | Location | +---------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Java Program to strip a filename of its extension after the last dot
- Select text after last slash in MySQL?
- Get the index of last substring in a given string in MySQL?
- Fetch ordered records after a specific limit in MySQL
- MySQL query to return a substring after delimiter?
- Query MySQL table and fetch rows posted before the last 3 days?
- Last Substring in Lexicographical Order in C++
- MySQL query to get a substring from a string except the last three characters?
- MySQL Query to remove all characters after last comma in string?
- MySQL query to replace a string after the last / in a column with directory links?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Get the substring before the last occurrence of a separator in Java
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- Extract numbers after the last hyphen in PHP?
- Substring() for Fields in MySQL?

Advertisements