D
D
Denioo2019-07-26 12:42:16
Oracle
Denioo, 2019-07-26 12:42:16

Single row subquery returns more than one row?

Hello everyone, I want to transfer data from a column of one table to a column of another table. I am writing this request.

update contract_city
set manager_id = 
(select contract_manager.manager_id
from contract_manager)

And an error is thrown
spoiler
Error starting at line : 1 in command -
update contract_city
set manager_id =
(select contract_manager.manager_id
from contract_manager
where contract_manager.contract_id = contract_city.contract_id)
Error report -
ORA-01427: подзапрос одиночной строки возвращает более одной строки

Don't tell me what the problem is.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Valsinats, 2019-07-26
@Denioo

See:

update contract_city
set manager_id = 
(select contract_manager.manager_id
from contract_manager)

Update all records in the contract_city table by setting EACH manager_id field to ( SELECT ALL contract_manager.manager_id)
See??
You set ALL RECORDS from another table for EACH record.
Try to match:
select contract_manager.manager_id
from contract_manager

Replace with FOR EXAMPLE:
select contract_manager.manager_id
from contract_manager
where contract_city.NAME_MANAGER = contract_manager.NAME_MANAGER

In general, find a common field for these tables, and link it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question