Dear all,
i need to update a table using same filed's multiple value.
Let: update test_table set column1=123 where column2=100,200,300......
I mean column 2 have multiple values.Now how i write the query??
Please help me.
try
update test_table set column1=123 where column2 IN(100,200,300)
look here for a tutorial:
http://www.webdevelopersnotes.com/tutorials/sql/tutorial_mysql_in_and_between.php3
If you mean that the match should happen where column2's value is one of the items in your list, use:
UPDATE test_table
SET column1=123
WHERE column2 IN (100,200,300, ...)
use FIND_IN_SET
FIND_IN_SET("id",test_table.column2)
Related
Does anyone know how to write the where conditions for the first row for dolphindb?
update table set x=100 where ?
you can use the dolphindb function rowNo:
update t set x=100 where rowNo(x)=0
I have a situation where I want to show a value that corresponds to one field in a table but in all rows. What is better is to show you an example in a screenshot:
What I want is to have the value of 3807 in every row? How can I do that?
THank you in advance.
Try using MAX as an analytic function:
SELECT
site_id,
bt_max_speed,
MAX(bt_max_speed_on_site_coverage) OVER (PARTITION BY site_id) bt_max_speed_on_site_coverage
FROM yourTable
ORDER BY site_id;
If you simply want to update one column so it has same value for all rows you can just use UPDATE without any conditions
UPDATE <table_name> SET <column_name> = <value>
In your case it would look like this, but with replaced with actual name of your table
UPDATE <table_name> SET bt_max_speed_on_site_coverage = 3807
First of all: It sounds pretty basic to me, but i did not find anything on this topic that comes close.
I am using pl-sql and have a table thats contains records. Now i have created a new column and want to insert an entry when specific conditions given. Something like this
insert into myTable (newColumn)
values (newValue)
where oldColumn = 'something';
Obviously this doesn't work.
Is this
possible with an insert statement or do i have to undo the whole row and rewrite it with the old values and the new one?
Thanks, newbie.
I think you want update, not insert:
updatE myTable
set newColumn = newValue
where oldColumn = 'something';
Please use update query instead of insert as your table is ready with records and you have added a new column to existing table that is having values in it.
syntax is as follows:
UPDATE new_column_name
SET new_column_name='Dummy value' where (condition)
You are trying to add values to a new column. But its corresponding row is already there. So you need to update the row, not insert. You can do like,
updatE myTable
set newColumn = newValue
where oldColumn = 'something';
I have a table which contains multiple columns.
Column 1 Column 2 Column 3
unique identifier alphanumerical value numerical value
The unique identifier is currently using the values from Column 2. If I wanted to use the values from Column 3 instead, which would be better suited for my situation? Replace or Update? Or is there another way I should go about doing this.
I'm using TOAD for Oracle for what it is worth.
Thank you.
Turns out what the OP wanted to do was simply set column1 to the value in column3, no replace was necessary. Just a straight update, as in:
UPDATE TheTable SET column1 = column3;
IF
you want to make a change in the table THEN
use UPDATE
ELSE IF
you want to just view the column1 values mapped with column3 values for particular instance THEN
use INSERT
The otherway around use UPDATE to change the contents of table, whereas replace is a function which really doesnt makes any changes in the contents of the table but just shows u the changed output.
You would use both.
update sometable set column1 = replace(column1,column2,column3)
You might want to do the following first to make sure you're replacing what you want to replace:
select replace(column1,column2,column3) from sometable
If only one row with a distinct field is to be updated,I can use:
insert into tab(..) value(..) on duplicate key update ...
But now it's not the case,I need to update 4 rows inside the same table,which have its field "accountId" equal to $_SESSION['accountId'].
What I can get out of my mind at the moment is:
delete from tab where accountId = $_SESSION['accountId'],
then insert the new rows.
Which obviously is not the best solution.
Has someone a better idea about this?
Use the update just like that!
update tab set col1 = 'value' where accountId = $_SESSION['accountId']
Moreover, MySQL allows you to do an update with a join, if that makes your life a bit easier:
update
tab t
inner join accounts a on
t.accountid = a.accountid
set
t.col1 = 'value'
where
a.accountname = 'Tom'
Based on your question, it seems like you should review the Update Statement.
Insert is used to put new rows in - not update them. Delete is used to remove. And Update is used to modify existing rows. Using "Insert On Duplicate Key Update" is a hackish way to modify rows, and is poor form to use when you know the row is already there.
load all of the values in to a temporary table.
UPDATE all of the values using a JOIN.
INSERT all of the values from the temp table that don't exist in the target table.
You can use replace statement. This will work as a DELETE followed by INSERT