I have a table where there is a column named "backfill_target" and its value is 1 but I need to change this to 20 for all 300 rows, how would I do this?
EDIT:
Here is a simplified version of my table
ID|name |backfill_target|first_record|second_record
0 | test| 1 |52 |54
try,
UPDATE tableName
SET backfill_target = 20
WHERE backfill_target = 1
Assuming you want to update every row.
UPDATE table SET backfill_target = 20
Related
i'm looking to figure out how i can update a row like a LIMIT 2,2 on a select
there is a little example:
col1 | col2
5 10
5 10
5 10
I want to update the 2nd row like this:
col1 | col2
5 10
1 10
5 10
i know the row number so i want something like that:
UPDATE table
SET col1 = 1
WHERE col1 = 5
LIMIT 2, 1
we cant use limit but i know this is achievable, HeidiSQL can do it and i'm trying to figure out how they are doing
thanks
If you need to update particular rows, you need a column or columns that can be used as primary key.
SQL works on sets of rows and you can only update rows that can be identified as belonging to the set.
For example, you can
UPDATE Customers SET Preferred=True WHERE TotalSales > 1000
which will set the "Preferred" flag for any customers that have sales over 1000. This might be one customer or a million or none.
The only way to do the single row update you asked about is to have some way to identify the row. In many database servers you can configure an IDENTITY or SEQUENCE column that will auto-assign each row a unique ID.
You can add an ID column with the IDENTITY property set, which would get you:
ID | col1 | col2
1 5 10
2 5 10
3 5 10
So updating that particular row would be:
UPDATE table SET col1 = 1 WHERE ID = 2
I am runnning a Postgres and Mysql server and I have table:
id | name | age | old_age
1 abc 20
I want to update column age with 21 with storing old value 20 into old_age column.
I can fetch the row and read the value of age and then update but that will require running 2 queries. 1 select and 1 update. Is there any way we can update in 1 query? I just want to copy age to old_age.
Just do
UPDATE TableName SET old_age=age, age=21 WHERE
In a MySQL database,
I have a table License with a few example rows as presented below:
ID | Key | Location
1 25 C:/Public/lics/1885-0001.lic
3 21 C:/Public/lics/1885-0006.lic
There are many such rows, which I would like to modify as given below:
ID | Key | Location
1 25 C:/Licenses/1885-0001.lic
3 21 C:/Licenses/1885-0006.lic
One of the columns from all the rows get modified. How do I update the table to make this change across all rows.
Judging from the docs I posted in my comment, I think you should do something like this:
UPDATE License SET Location = REPLACE(Location, 'C:/Public/lics', 'C:/Licenses');
UPDATE License
SET Value = REPLACE(Location, 'Public/lics', 'Licenses')
I have a table looks like below:
id name value newColumn
============================
1 Joe 22 null
2 Derk 30 null
newColumn is a newly added column and I would like to update the data for each and every rows with a specific format: concat value and a specific string -CIF
End result should be something like below:
id name value newColumn
============================
1 Joe 22 22-CIF
2 Derk 30 30-CIF
May I know how to construct such update query in mySQL?
This is a fairly basic update:
update table t
set newColumn = concat(value, '-CIF');
I have the following table structure:
table "sample"
objectID | objectValues
1 | 5,6,7
2 | 6,7,5,8
3 | 5
4 | 7,8,9,5,6
5 | 10,11
6 | 5
So, I want to delete all ",5" or "5," values from "objectValues" and delete all columns which theirs "objectValues" value is only "5". How can I do this?
You can try a tricky method using four queries to make this change.
first query for delete all rows when object value is 5
DELETE FROM sample WHERE objectValues = 5;
second for update rows when is a value is in all places except first and last
UPDATE sample
SET objectValues = REPLACE(objectValues , ',5,', ',');
third when the value 5 is on the first place
UPDATE sample
SET objectValues = LEFT(objectValues, LENGTH(objectValues)-2)
WHERE objectValues LIKE '5,%';
and last query when the value 5 is on the last place
UPDATE sample
SET objectValues = RIGHT(objectValues, LENGTH(objectValues)-2)
WHERE objectValues LIKE '%,5';
Try this
delete from table where find_in_set(5,objectValues)>0;