0

I am having difficulty creating an INSERT query.

Employee_record table has column manager_id and manager_name

Node table has column manager_id

I want to insert manager_name in Node table.

How to achieve this?

nbk
  • 45,398
  • 8
  • 30
  • 47
  • How can you insert `manager_name` into the `Node` table when it only has a `manager_id` column? – Barmar Aug 01 '22 at 21:33
  • why would you do that as you can link the emply table evrytime to the note table, you can grab the name. everything else is redundnat – nbk Aug 01 '22 at 21:34
  • Why does the `employee_record` table have both `manager_id` and `manager_name`? It only needs `manager_id`. You can use a self-join to get the manager's name if you need it. This is a violation of normalization. – Barmar Aug 01 '22 at 21:37
  • Check https://stackoverflow.com/a/1262848/16702058 – Hi computer Aug 01 '22 at 23:25

2 Answers2

0

alter you node table alter table node add manager_name varchar2(90); then use this insert query if you have to insert only manager name insert into node (manager_name) select manager_name from Employee_record where manager_id = ?

pass id at ?

0

if you just want to add a new column to the table:

ALTER TABLE node 
ADD COLUMN manager_name VARCHAR(255);

you dont have to use specifically 255, thats just a standard ive come to use.

then if you want to add the same records from the manager_name column from the employee_record table into the newly created manager_name column in the node table:

INSERT INTO node(manager_name)
SELECT manager_name
FROM employee_record
WHERE *conditions*

for conditions, you can specify if you only want certain names to be inserted, such as WHERE manager_id = 12345.

However, as some of the comments have said, doing this will just make two identical tables which doesn't seem have much use from what i can tell about the situation.

DAking
  • 7
  • 3