0

I am wondering what I am doing wrong. I have 2 tables used in this problem: ODETAILS and PARTS.
ODETAILS has the following columns: ONO, PNO, QTY, COST

PARTS has the following columns: PNO, PNAME, QOH, PRICE, OLEVEL

I am trying to update the column COST in ODETAILS so that the COST = QTY * PRICE
PRICE is found in PARTS. But how can I connect those two tables. I am having a brain fart because this is what I tried:

UPDATE ODETAILS
SET COST = QTY * 
    (SELECT PRICE
    FROM PARTS
    WHERE PNO =
        (SELECT PNO
        FROM ODETAILS
        WHERE NOT PNO= NULL
        )
    )
WHERE NOT PNO = NULL;

0

4 Answers 4

1

I think the second subquery is wrong becasue it can give you multiple rows and it is unnecesary:

update odetails
set cost = qty * (select price from parts where parts.pno = odetails.pno)
where pno is not null
Sign up to request clarification or add additional context in comments.

Comments

0

In mysql at least, you can't reopen the table you're updating in a subselect. Try this:

UPDATE ODETAILS o
JOIN   PARTS p
ON     o.PNO = p.PNO
SET    o.COST = o.QTY * p.PRICE

Comments

0

Depending on Database settings (null yield null) , you can not compare with equal, not equal operator. Use

where PNO is not null

Comments

0

figured it out. thanks anyway.

UPDATE ODETAILS
SET COST = QTY * (
   SELECT PRICE
   FROM PARTS
   WHERE (PARTS.PNO=ODETAILS.PNO)
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.