Satish Satish - 5 months ago 14
MySQL Question

Generic MySQL Query for Trimming Column Data

I have a Table in which one of the column contains data as follows:

file1 (1.1.1.1).txt
file2 (1.1.1.2).txt
file3 (1.1.1.3).txt
file4 (1.1.1.4).txt


I want to trim off the text from Opening parenthesis. After trimming, the Updated data should be as follows:

file1
file2
file3
file4


Since the Records are in Hundreds, is there a Generic way to Trim off the unwanted text? How the Query is written in MySQL

Answer

Your SQL query could be like this:

         UPDATE your_table_here SET file_name = RTRIM(SUBSTRING(file_name, 1, LOCATE('(', file_name)) - 1 );

Just replace file_name and your_table

Comments