Tuesday, August 3, 2021

Update one table from another table

 --update one table from another table, here qc_testmast table will update from qc_testmast_blank_rate table.

--we can use two types query:query no:1

UPDATE qc_testmast a

   SET (unitprice, mrrno) =

          (SELECT b.unitprice, b.mrrno

             FROM qc_testmast_blank_rate b

            WHERE     a.ITEMCODE = b.itemcode

                  AND a.QC_REFNO = b.QC_REFNO

                  AND a.GRNNO = b.GRNNO)

 WHERE (a.itemcode, a.qc_refno) IN (SELECT c.itemcode, c.qc_refno

                                      FROM qc_testmast_blank_rate c)

                                      

--Query Number:2

================


UPDATE qc_testmast a

   SET unitprice =

          (SELECT b.unitprice

             FROM  qc_testmast_blank_rate b

            WHERE     a.ITEMCODE = b.itemcode

                  AND a.QC_REFNO = b.QC_REFNO

                  AND a.GRNNO = b.GRNNO)

                  --AND ROWNUM = 1)

 WHERE EXISTS

          (SELECT b.QC_REFNO

             FROM qc_testmast_blank_rate b

            WHERE     a.ITEMCODE = b.itemcode

                  AND a.QC_REFNO = b.QC_REFNO

                  AND a.GRNNO = b.GRNNO

No comments:

Post a Comment