update replace command in mysql - mysql

All,
In a field named(path) in The table named is recn i have the follwoing data /home/user1/Computer-Science-10_1-10_7-17//html/Compu.html
how do i replace
/home/user1/Computer-Science-10_1-10_7-17//html/Compu.html with /home/user1/path/files/Computer-Science-10_1-10_7-17//html/Compu.html in mysql
Also There are many rows like /home/user1 which i have to replace with /home/user1/path/files
Thanks.....

Is this what you want?
UPDATE mytable SET mycolumn
= REPLACE(mycolumn, '/home/user1','/home/user1/path/files');

Related

Update column with value from another column

In a SQL table I have two columns: the first contain a path and the second contains a value.
colunm1
/path/
colunm2
12345
I need to update the first column with the value that exists in the second column. to get this result :
colunm1
/path/12456/
I tried this, but not working
update tablename p
set p.colunm1 = "/path/'colunm2'/"
You have the right idea, but the SQL you shared uses column2 as a string literal. You could use the concat to concatenate the two columns:
UPDATE tablename
SET column1 = CONCAT(column1, column2)
You have to use CONCAT
update tablename p
set p.colunm1 = CONCAT("/path/",`colunm2`,"/");

Delete some characters from a column in MySQL

I have ONE column in MySQl table which contains this format:
https://open.spotify.com/track/AAABBBCCC
and I'd like to leave just AAABBBCCC, and not the entire column! The last parte is always the same.
Is that possible? Thanks and sorry for my english!
You can use SQL REPLACE function to do that.
UPDATE your_table_name
SET your_column_name = REPLACE(your_column_name, 'https://open.spotify.com/track/', '')
For more information you can read SQL statement to remove part of a string
Use REPLACE to delete the wanted text from your column:
UPDATE Table1 SET Column1 = REPLACE(Column1,'https://open.spotify.com/track/','')

MySQL: UPDATE column WHERE column STARTS WITH " " (Blankspace)

I need to search and UPDATE my database for column values starting with a blankspace..
SQL
UPDATE table
SET column substring(column, 1)
WHERE column has blankspace
How can i do this?
EDIT
Oh yeah.
Reason is to erase blankspace...
Use LTRIM() function to remove starting blank spaces.
Try this:
UPDATE table SET column = LTRIM(column)
I think you should be explicit and use like:
UPDATE table
SET column = substring(column, 1)
WHERE column like ' %';

Adding text to each column of MYSQL Database

I have a database table in MYSQL with around 1000 rows. In the table I have a column called 'overview'. In each row, this column has some value and at the end of that value I have a specific line (text) starting with: 'Source...'
Now what I want is, I want to remove this line from each column and replace it with some other text content.
I believe it can be accomplished with some smart query.
You can simply use REPLACE in your query like this
UPDATE your_table SET col_name = REPLACE(col_name , ‘Source...’, ‘new_val’)
WHERE col_name LIKE '%Source...';
Check Out the SQLFIDDLE.
MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string).
The syntax of REPLACE is:
REPLACE (text_string, from_string, to_string)
In your case, you can do this way:
UPDATE `tableName` SET `column` = REPLACE(column , 'Source...', 'Replaced Value')
Use Replace
update TBL
set overview = Replace(picture, 'Source..', 'replacement')
keep a backup of the table before anything.Or you can do it on a copy.
you can do this by following:
update table_name set col_name = replace(column_name , ‘Source...’, ‘Replaced String...’);

Identify and update values in MySQL

I have a table full of these types of values
AU$97-AU$130
I would like to replace the values with the everything before the dash
So the above would become
AU$97
I know how to do this using PHP/MySQL using a few separate steps but is there a one time query in MySQL to do this?
Thanks in advance
SELECT SUBSTRING_INDEX(col_name, '-',1) from tblNAME
EDIT:
To update the col
UPDATE tblNAME set col_name=SUBSTRING_INDEX(col_name, '-',1);
UPDATE tbl_name SET col_name=SUBSTRING_INDEX(col_name, '-',1);
Assuming you want everything with a dash to be affected:
UPDATE my_table SET col = SUBSTRING_INDEX(col, '-',1)