
- 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
How to get everything before the last occurrence of a character in MySQL?
You can use below syntax. Following is the syntax −
update yourTableName set yourColumnName=REVERSE(SUBSTRING(REVERSE(yourColumnName), INSTR(REVERSE(yourColumnName), '.')));
Let us first create a table −
mysql> create table DemoTable -> ( -> Words text -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Value1. Value2 .Value3.Value4.Value5'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------------------------------------+ | Words | +--------------------------------------+ | Value1. Value2 .Value3.Value4.Value5 | +--------------------------------------+ 1 row in set (0.00 sec)
Here is the query to get everything before the last occurrence of a character in MySQL −
mysql> update DemoTable -> set Words=REVERSE(SUBSTRING(REVERSE(Words), INSTR(REVERSE(Words),'.'))); Query OK, 1 row affected (0.13 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------------------------------+ | Words | +--------------------------------+ | Value1. Value2 .Value3.Value4. | +--------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Get the substring before the last occurrence of a separator in Java
- Finding the last occurrence of a character in a String in Java
- MySQL query to get all characters before a specific character hyphen
- Get left part of the string on the basis of last occurrence of delimiter in MySQL?
- Get the last occurrence of a substring within a string in Arduino
- How to select everything before @ in an email-id with in MySQL?
- How to get the last index of an occurrence of the specified value in a string in JavaScript?
- How to ORDER BY last 2 character string in MySQL?
- How to get last day of the current month in MySQL?
- How to get last day of the previous month in MySQL?
- How to get last day of the next month in MySQL?
- How to find the last occurrence of an element in a Java List?
- How to replace the last occurrence of an expression in a string in Python?
- MySQL query to remove everything except the last 7 characters in column record
- MySQL query to select everything to left of last space in a column with name records

Advertisements