I would like you to run a script where the existing fields
d1_image_url
should be changed from URL to image name
For example
Following column contains
abc.com/r_doc/58/567889.jpeg
i want only 567889.jpeg will print.
Note- image name will be unique for 10 thousand records.
I am trying with following update query but its not giving me unique image name.
update cl_master set d1_image_url = substring_index('images/r_doc/58/567889.jpg','/',-1)
where the cl_master is table name and d1_image_url is column name.
can any one give me solution for this.
You should use your column name in substring function as parameter.
update cl_master set d1_image_url = substring_index(d1_image_url, '/', -1)
This should work:
update cl_master set d1_image_url = SUBSTRING_INDEX(d1_image_url, '\\', -1)
Related
In my database table, Due to some mistake same row has been entered twice, But it is now having one column value with some appended numeric value in the duplicate entry.
For example,
If my table has a column named filename, Then in one row it has value 'some-random-name.pdf'.
And in the duplicate row, it has value 'some-random-name-1532.pdf'.
I need to identify all such records. Please note that there can be any or zero number of dash(-) in the filename. So Like query something like '%-____-%.pdf did not help me.
Assuming that complete filename contains only one dot between name and extension you may try this:
WHERE SUBSTRING_INDEX(t1.value, '.', -1) = SUBSTRING_INDEX(t2.value, '.', -1)
AND LOCATE(SUBSTRING_INDEX(t1.value, '.', 1), SUBSTRING_INDEX(t2.value, '.', 1)) = 1
I have a column with links in my table. Some links have a string like /?source=rss&....
So I want to remove this string /?source=rss and what comes after it.
So if the link looks like this https://website.com/?source=ress&id=123&name=john
It should be https://website.com
I searched about it but only found replace and remove functions, And they won't work as the string is variable and not the same in every link.
I found this UPDATE MyTable SET column = REPLACE(column, ' ', '') WHERE column LIKE '%%'
The database is MYSQL and I'm using SQL queries there
Use substring_index():
UPDATE MyTable
SET column = SUBSTRING_INDEX(column, '/?', 1)
WHERE column LIKE '%/?%';
Hi I am using the following sql query to select by length of the company column which works but i am stuck on how to empty/remove those matched column strings. I dont want to delete the row just remove the 1 character the below sql query matched.
select company FROM grocer_append WHERE CHAR_LENGTH(company) = 1
Thanks for your help
If I'm reading right, you just want to remove the character and have company be blank? This would work:
update grocer_append
set company=''
WHERE CHAR_LENGTH(company) = 1;
Lets say that you have the following stored in table:
{2:22}{4:5}{34:4}
I what to delete {4:5} from this string but the system dosent know what the number after the ":" is just the first one. The query looks something like this:
UPDATE tbl SET this = REPLACE(this,'{4:??}','') WHERE id = 1;
What do i need to put in ?? place to return the following result?
{2:22}{34:4}
Here's one way to do it using LEFT, SUBSTRING, LOCATE and REPLACE:
update yourtable
set yourcolumn =
replace(yourcolumn,
Left(
Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)),
Locate('}',Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)))),
'')
SQL Fiddle Demo
Imagine that you have a column with a bunch of fields like this:
ab
abc
abcd
...
I would like to transform these fields using a single query to something like this:
a_b
ab_c
abc_d
...
That is, inserting an underscore just before the last letter.
I could do it in a one by one basis:
update test set name = 'a_b' where name ='ab';
update test set name = 'ab_c' where name ='abc';
update test set name = 'abc_d' where name ='abcd';
But being a high number of fields to update, I figure there must be a better way to do this.
Try this query -
UPDATE test SET name = INSERT(name, LENGTH(name), 0, '_');
Use some of the string manipulation functions, something like:
SET fieldname = CONCAT(LEFT(fieldname, LENGTH(fieldname)-1),"_",RIGHT(fieldname,1))
You could use the SUBSTRING AND LENGTH functions:
UPDATE test
SET name = SUBSTRING(name, 0, LENGTH(name) - 1) + '_' + SUBSTRING(name, -1)