Separate compress data in two different column - mysql

I am getting data piled up in only one column and i want to separate the information
This is what im doing:
UPDATE `Inventario`.`inventario`
SET `DESCRIPCION`='MONITOR 17\",,DELL '
WHERE `ID`='473';
for example DELL should be in another column

You can set multiple columns in an UPDATE statement:
UPDATE `Inventario`.`inventario`
SET `DESCRIPCION`='MONITOR 17"',
`Manufacturer` = 'DELL'
WHERE `ID`='473';
BTW, you don't need to escape " inside a string delimited with '.

UPDATE Inventario.inventario SET DESCRIPCION='MONITOR 17\"', Manufacturer = 'DELL' WHERE ID='473';
If your table has the column with the name manufacturer.

Related

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/','')

How to delete specific value from a column in SQL row?

I am a beginner in SQL. Currently, I am working with a SQL database that has two columns. The first column specifies the id. The second column specifies a list of people separated by the delimiter "#d#" So, the column looks something like "John#d#Jack#d#Prince"
I need to delete a specific name from this list. Suppose, I am deleting prince from the list. I want my row to look like John#d#Jack after the delete operation. I was researching solutions for this procedure and I found couple resources. I learned about this approach "UPDATE TABLE SET columnName = null WHERE YourCondition" As a result, I can change the whole column to null, but I don't know how to retain the string and only delete the specified value.
You can use replace function
update yourTable set yourField = replace(replace(yourField, 'Prince', ''), '##' , '#') where yourCondition;
First replace "delete" the name you want to, second replace "delete" deleted name's delimiter.
You can do this using:
update t
set list = trim(both '#' from replace(concat('#', list, '#'), concat('#', 'prince', '#'), '#'))
where concat('#', list, '#') like concat('%#', 'prince', '#%');
You can replace 'prince' with a variable or whatever you want to replace.
If I am not mistaken the command you are looking for is
UPDATE TABLE set columnName = "John#d#Jack" WHERE YourCondition
Or do you want a more general approach?

Trying to use update query to only update fields that are blank in Microsoft Access

I am trying to use an update query to update fields from one table to another for fields but only if the fields in the table that i am updating into is blank. If they contain information, I do not want to overwrite the existing data
e.g
Field: Name
Table: Table 1
Update to: [Table2.][Name]
Criteria:
I am unsure of what to put in the criteria. I tried, 'Is Null', Like "".
Here is an example:
UPDATE MyTable SET MyTable.FieldB = "MyNewValue" WHERE (((MyTable.FieldB) Is Null));
Looking at the Query from within Access, you can switch to SQL view. You just need to put Is Null in the criteria column: UPDATE MyTable SET MyTable.FieldB = "MyNewValue" WHERE (((MyTable.FieldB) Is Null));
Furthermore, you can just write Is Null on alternate lines and it will count as OR.

Mysql update rows dynamically based on column input

I have the following issue. I have a table called titles with the following structure:
id int(10),
name varchar(100),
At some point later we added a new column called modified_name. It is defined as the same as name except that it is lower case and has all of the spaces replaced with a -. We added this column and so we needed to now get the right modified name value into each record of that column. To do this we wrote a PHP script that handled that by loading in values from the database and processing them, but that is highly inefficient. Is it possible to write a single UPDATE query that would add the correct value to each record in the titles table. I can think of ways to do this with a stored procedure and a while loop there in, but I want to know if something more efficient is possible. It there any way to achieve something like the following:
UPDATE `titles`
SET
`modified_name` = LOWER(REPLACE(SELECT `name` FROM `titles` WHERE id = PRESENT_VALUE), ' ', '-');
The goal being to SET the modified_title column of every record in the titles table to a unique value that results from that record's name column as followed:
# Before modification update query
name = "Hello Goodbye"
modified_name = ""
# After modification update
name = "Hello Goodbye"
modified_name = "hello-goodbye"
Thank you for your help, any advice on how best to do this would be appreciated.
UPDATE `titles` SET `modified_name` = LOWER(REPLACE(`name`, ' ', '-'))

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...’);