I have an Employee table where DEPTCODE is null.
ID NAME AGE DEPTID DEPTCODE
---- ---------- ----- ---------- -------
1 Paul 32 2
2 Allen 25 1
And a Department table like this:
ID DEPTNAME DEPTCODE
---- ---------- -----
1 HR DEP-01
2 ADMIN DEP-02
How to update DEPTCODE in the Employee table by querying DEPTCODE from the Department table?
I have tried this;
DO $$
BEGIN
FOR depart IN
SELECT * FROM schema."Department"
LOOP
Update table schema."Employee" set "DEPTCODE"=depart."DEPTCODE"
where "DEPTID"=depart."ID";
END LOOP;
END; $$