I have got Two Tables
Product (Id, Name, CCode)
Category (CCode, CatName) – No Primary Key
Insert Into ProductNew (DW_Prod_Id, ProdId, ProdName, CC, CName)
Select Dw_Prod_Id.Nextval, Id, Name, CCode,
(Select CatName From Category cc, Product p Where cc.CCode IN p.CatCode Group By CatName )From Product;
SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 – “single-row subquery returns more than one row”
I am getting the above error Because my SubQuery returns more than one row.
I would like to Match the CatCode of each row from Product table to the Category Table so that I can obtain the CatName and then Insert rows into my New Table 🙂
if product can have only one category :
And you can correct your table name
to ProductNew 😉
EDIT :
But if, as @Gordon Linoff pointed, you have duplicates CCode, this won’t work.
If you don’t want a primary key on Category table, add at least a unique constraint (you’ll have to clean your datas first)
EDIT 2 :
But the proper way would be :
Add an Id in Category as PK, and use it as Category_ID FK in Product (if CCode can change)
With the unique constraint on CCode.