I Have a table in SQL with 2 columns:
ID, Date
Then I had to add another, column, "Description", that can be NULL. So my table will look like:
ID. Date. Description
01. 2000/08/07. NULL
02. 2000/03/01. NULL
03. 2001/08/17. NULL
..
99 2002/12/12. NULL
I have to update the column "Description" with a csv file.
I can't delete this table and each row should have a description
Is there a way to do that in workbench?
The final result should be:
ID. Date. Description
01. 2000/08/07. XY
02. 2000/03/01. XYZ
03. 2001/08/17. ZY
..
99 2002/12/12. ZX
Load the CSV file into a table, using load data infile. Presumably, the file has an id to link it to the existing data. Then use join:
update t join
csv_table c
on t.id = c.id
set t.description = c.description;
Import your csv as a table i.e. table-1. This table should have atleast one common column having distinct values as of the table you mentioned above. Then on the basis of joining, you may update your table for description attribute.
Related
I have two schemas in the same database. I want to update a table in one schema based on the table in another schema where the column value matches.
The structure of my database is as follows.
structure of database
As an example, this is my table named "p" in 1st schema that is "public" and have column "id" and "name"
id name
3 Loral
1 Kim
2 Shawn
and this is the second table named "t" in the second schema that is "t_sc" and have column "id" and "name" but the names are different than table "p"
id name
1 kylie
3 deny
2 tom
Now I want to update table "p" names according to table "t" names where the id matches.
I have tried the following query
update p set p.Name = t_sc.t.Name WHERE p.ID = t_sc.t.ID
but got the following error
ERROR: missing FROM-clause entry for table "t"
I have tried multiple other ways too but I am not able to get the desired result. I am using Navicat for query and the database is Postgresql.
If this is really MySQL, you need to call your schema(s) specifically.
You can thank this user for the example below:
Update a column on a table from a table on another schema MySql
update schema1.table1
inner join schema2.table2
on schema1.table1.IDColumn = schema2.table2.IDColumn
set schema1.table1.column1 = schema2.table2.column2
I have found the answer myself. So I thought maybe I should post it for future visitors.
The query will be
UPDATE public.p a
SET name=b.name
FROM t_sc.t b
WHERE a.id=b.id
I was using the alias with column name p.Name of the Table which I want to update. Also I was using the schema name at the wrong time t_sc.t.Name It was causing the error.
I have a table with 62 columns and 22k rows. I need to change every row of the first column. I have the new data on a text file. How can I do it?
I have tried with 'replace' and 'update' but I can't find the way to substitute using the text file and it's impossible to change it manually.
Let's say your original table looks like this (it would be helpful if you'd post snippets or samples):
Name ID
==== ==
Mary 1
John 2
Dave 3
Suzy 4
And your text file:
Mari
Juan
Daav
Suzi
If you know that the sequence of lines in the text file is the same as the table (or you can arrange the table in that sequence by query), then do the following:
Create a temporary table by importing the text file. If necessary add a unique ID that you can use as a join criteria.
Write an update query that links the tables as needed:
UPDATE table a
LEFT JOIN temp_table b
ON a.id = b.id
SET a.name = b.name;
Research how to add a primary or unique key to either table as needed to create the join condition.
I am trying to delete a value from a field in workbench.
Getting an error
Unknown table nhs in multi delete
I am trying to "NULL" a single filed in a single table.
DELETE nhs FROM persons WHERE oid = 123
I was expecting this to delete the record. Whats wrong? I am only trying to delete a value from a single field in one table.
I am trying to "NULL" a single filed in a single table
I hope you are looking for
UPDATE persons SET nhs = NULL WHERE oid = 123
DELETE FROM persons WHERE oid = 123, will remove the entire row, it can't delete a single column. To change a single column's value you need to use UPDATE statement.
I have 5 tables in Source.Each table have PK_ID.I have to populate into destination.I populated the table into destination but
I want to make a metadata_table in SSIS.The schema of metadata_table -
2 columns- a) table name b) last PK_ID of that table.
in table name column all the 5 table's name should be there and in PK_ID column , last PK_ID of respective table.
How can I do in SSIS. Please help
EDIT:
I need to update the destination table by populating newly inserted data in source table only by comparing PK_Id of source table with the Pk_Id of metatable as shown below
if(Pk_id(Source_table)>Pk_id(Meta_table))
then insert in Destination table(only those records having Pk_id greater than PK_id of metatable) and Update the metatable too by inserting Max(PK_id) of source table.
I would create a Dataflow for this. I would add 5 OLE DB Source objects, each would return the MAX (PK_ID) (assuming that meets the requirement - "last" is ambigous).
They would also each include a dummy join column e.g.
SELECT
1 AS DUMMY_KEY
, MAX ( PK_ID) AS PK_ID1
FROM TABLE1
Then I would add 4 Merge Join transformations. Each would join a pair of the OLE DB Source objects, using the DUMMY_KEY as the join.
The result would be a single row with the 5 "last PK_ID" columns.
I have two tables with a lot of fields
table - A
table - B
in table A only two fields are filled all other are empty, but exactly that fields are filled in table B
I would like to
UPDATE A, B set A.c = B.c, A.d = B.d .... WHERE ....
but there are a bout 100 columns, is there any way how to update all fields in A from B except 1 particular field ? Is there any way how to tell mysql left 1 particular fields in A as it is.
If field name in table A and B are same then you can just use excel to build the string.
Copy the entire structure of DB table A into excel as 1 column and then use excel formula with string concatenation to build the required string.
It should not be that difficult task.
From MySql end, you can review DELETE and INSERT option with help of temporary table. More details needed to think of solution at MySql end.