replace all column values equal to one string with another string - mysql

I have a MYSQL table called traceclasses and I have a column in this table called value with some of its cell values equal to E as shown below. I would like to replace all such values with U. Which query should I use to do this?

You are looking for update:
update t
set value = 'U'
where value = 'E';

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`,"/");

how to properly do the following update MYSQL statement?

i have a string with the following value
Germany,Sweeden,UAE
and i have an mysql row that have a value of one of this separated string with comma
as example a Country Row with a value Sweeden .
i have tried to use this sql statement to update a targeted row where its value is like one of this string separated with comma
hence if the row have a value of sweeden it should be updated sense sweeden value is include in the comma string
UPDATE CountryList SET Time= '100' WHERE Country LIKE '%Germany,Sweeden,UAE%'
but i couldn't update the targeted row using this syntax. any idea what is the correct syntax i should use ?
I think you want find_in_set():
update CountryList
set time = 100
where find_in_set(country, 'Germany,Sweeden,UAE')
This checks if country matches any of the values in the comma-separated row given as second argument to find_in_set().
Note that I removed the single quotes around the literal 100: if time is a number, then treat it as such (if it's a string instead, then keep the quotes).

Replace values with string mysql

I have a VARCHAR column in which some values end with the digit '5'. These
values may be of different lengths. I want to replace all such values
with the string 'UTR-5'. How can I do that?
Maybe not the fastest solution, but:
update myTable set value = 'UTR-5' where value like '%5'

mysql syntax for populating a column of an existing table and setting a default value for said column

I have a table and I have added a new column to it. I need to populate this new column and also set the default value for it.
The value of the new col is obtained by concatenating two strings based on the values of other columns:
the first string is the sum COL_1 + 10000
the second string is a obtained by stripping everything but the alphanumerics in COL_2
Update TABLE set NEW_COL = CONCAT ((SUM (10000 + COL_1)), (preg_replace('/[\s\W]+/','',COL_2)))
This will be the default value for the column
The reason your update is failing is that preg_replace() is not a valid MySQL function. That's a PHP function. Here's a relevant question that addresses that functionality in MySQL:
How to do a regular expression replace in MySQL?

How do I update the members of a MySQL SET Type?

I have a table of values, with one of the columns being of type SET.
If it currently has the members ('a', 'b', 'c', 'd'), how do I add 'e' to the possible values?
I realize that using a SET type is a little strange, and I'm unclear why one would use it instead of a foreign key to another table with the values of the set, but I didn't design the database in question, and can't change it that much.
Thanks for your help!
UPDATE: I want to update the SET type for all rows, not just one, if that helps.
To add an element to an existing SET use the CONCAT() function to add the new element to your comma separated list. To work with decimal values, we can use the bitwise OR operator |.
UPDATE set_test SET myset = CONCAT(myset,",Travel")
WHERE rowid = 3;
or
UPDATE set_test SET myset = myset | 1 WHERE rowid = 3;
You can also use the CONCAT_WS() function, which handles list separators for us:
UPDATE set_test SET myset = CONCAT_WS(',',myset,'Dancing')
WHERE rowid = 6;
You want to add 'e' to the allowable values in that set field, or it's already there and you want to add 'e' to the current value of the set field in that table?
If it's not already an allowed value, then you'll have to do an ALTER TABLE and redefine the field:
ALTER TABLE set_test CHANGE myset myset SET('a','b','c','d','e');
(yes, 'myset' is put in there twice, it's a "currentname newname" sort of thing.)
Otherwise just do an UPDATE TABLE and concat the field with 'e' as the previous answer says.