Identify and update values in MySQL - 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)

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 i can update the value for any key by adding on the current value

I have a table X where there are values for approver_grp as 210061280,200019820 for one row , 213044040 for another and so on ..
I wish to add 212031856 and 21202589 to the existing values.
Can you please suggest what sql statement can be used to update these values.
Thanks in advance
use CONCAT() and if you want update specific row only means use where condition otherwise leave it .
update table_name set column_name=concat(column_name,',','212031856,21202589') where id= specific_row_id

MySQL how to insert one value without affecting other values

In my table "accounts" I have four columns like
user, pass, column1, column2
I need to insert value into column2, where user='special_user_value'.
How can I do this?
UPDATE accounts
SET column2 = 'New Value'
WHERE user = 'special_user_value';
You don't "insert values" into a column. You insert a row, that has a value for all the columns you specified in the table creation; Just like a real table, or excel sheet for that matter.
If you need to change a column value for a specific row, you can use UPDATE:
UPDATE table_name SET column2='new value' WHERE user='special_user_value'
This is a really basic example. If you follow the link I provided for UPDATE, you may learn more about changing table values for a specific row.
If are you looking for actually inserting a new row with a specific value for that column, there's INSERT INTO you could follow to achieve that.
Use update Query like:
Update table_nm set field1=value1, Field2=value2 Where condition;
UPDATE Accounts SET column2='NewValue' WHERE user='special_user_value'

Mysql + Update to table (same time) with Join

I believe this is possible but I haven't done it before.
I need to update 2 tables and I want to use one MySQL command. I also have a join field.
UPDATE static_site_articles SET domainname='a',language='b',url='domain',toptext='c',bottomtext='d' WHERE id='10;
UPDATE static_site_articles_meta SET url='domain',title='e',description='f',keywords='g';
They join with the url='domain'.
How can I construct this into a single UPDATE command line?
A push in the right direction would be greatly appreciated.
thx
http://dev.mysql.com/doc/refman/5.1/de/insert-on-duplicate.html
INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;

update replace command in 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');