How to update the first row of a table in dolphindb? - sql

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

Related

SQL update set table if value in table A is equals to value in table B

this query is working fine.
UPDATE data
SET unit_id='a3110a89'
WHERE unit_id='7d18289f';
Now, I need to run this query over 30 times
so I made csv file import it to the DB with this command:
COPY mytable FROM 'D:/test.csv' WITH CSV HEADER DELIMITER AS ','
Now I have table called my table with 2 columns OLD and NEW
i want to search the table "data" in column unit_id anywhere there if the value equals to the value in table "mytable.old" replace it with the value "mytable.new" on the same row.
I tried to run this query but I get an error:
UPDATE data
SET unit_id=(SELECT mytable."old" FROM public.mytable)
WHERE unit_id=(SELECT mytable."new" FROM public.mytable)
error:
more than one row returned by a subquery used as an expression
I think i'm just trying to do it in the wrong way...
thx for the help!
by the way Im using PostgreSQL
Your subqueries need to be correlated to the outer update:
UPDATE data
SET unit_id = (SELECT mytable."new" FROM public.mytable where data.old = mytable.old)
WHERE unit_id in (SELECT mytable."old" FROM public.mytable);
That is, set the unit_id to the "new" value, when you find the "old" value in the table.
Can you try like this,
UPDATE data A
SET A.unit_id=B.old
FROM (SELECT mytable."old",mytable."new" FROM public.mytable) B
WHERE A.unit_id=B.new
UPDATE data A
SET unit_id = B."old"
FROM public.mytable B
WHERE A.unit_id = B."new"
;
BTW: it looks like you also have old and new swapped in your question. Do you really want A's value to be set to B's old field?

Delete a specific field from a database

How can I delete the value of a field from a database, using query code? I only know where the field is located in the database. (ex: column['phone number']row[3])
It should be something like this "DELETE FROM ... WHERE ..."
There is nothing like delete the field in database i.e. if you want to remove the complete row then you can do that easily like this
DELETE FROM TABLE WHERE COLUMN1=#myValue
But if you wanted to remove one value of the row in that case you should update that value as NULL
UPDATE TABLE SET COLUMN1=NULL WHERE COLUMN1=#myValue
I have used where clause from my imagination. you can always use whatever you want.
The DELETE statement allows you to delete RECORDS.
When you want to set a field to an empty value, use the UPDATE statement.
See this for more info.
UPDATE [YOUR_TABLE] SET [YOUR_FIELD] = NULL WHERE [YOUR_PRIMARY_KEY] = VALUE
Yes first you need to use delete command. Then after this insert update command then only the records will be deleted from the database. I agree that you have deleted records but its not showing because you haven't updated it.

how to update multiple column in a single table

I have created a table having three colums GsID,ALlowance and amount
Begin if exists(select * from [dbo].[HRAllowances] where GdId=#GdId) begin
update [dbo].[HRAllowances] set
Amount=#Amount where GdId=#GdId end
end
this only works for one particular row..
i want to allow user to update amount for all rows
After seeing your comment, if you wish to update all Amount fields for all records, remove your WHERE clause as this is filtering records by ones where GdId=#GdId:
UPDATE [dbo].[HRAllowances]
SET Amount=#Amount
If you want to update all the rows than you have to remove where condition that is
where GdId=#GdId from you query.
Like this :-
update [dbo].[HRAllowances] set Amount=#Amount
I hope it will works!!

Convert value in all rows to VARBINARY(50)

I want to upgrade all columns in a table, what I am aiming to do is retreive a column from the row it will update then update it, something like:
update works
set encrpyted_item_no = (CAST(RTrim((
select unencrypted_item_no
from works
where name = name
) AS VARBINARY(50))
I know that query is wrong, it's just an example to show you what I am aiming to do.
I want it to select the column unencrypted_item_no from its row then update that same row with the data it gets from unencrypted_item_no, doing this for the whole table.
How would I accomplish this?
You shouldn't need to do a sub-select, referencing the other column in the set will work on a row by row basis, ie:
UPDATE works
SET encrpyted_item_no = CAST(RTrim(unencrypted_item_no) AS varbinary(50))
Shouldn't this be enough ?
update works
set encrypted_item_no = CAST(RTrim(unencrypted_item_no) AS VARBINARY(50))

update column using where clause a same field's multipul values

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)