I need to copy some data from one table to another but I need to use a WHERE clause in order to have it all work properly.
tbl_1 has classID vendorID category_id (EDIT: category_id is currently empty, this is what I’m trying to copy from the other table…) and departmentID
tbl_2 has class_code department_id and category_id
I want to grab the category_id in tbl_2 and put it into tbl_1 where the tbl_1.classID = tbl_2.class_code AND tbl_1.departmentID = tbl_2.department_id
I tried using:
INSERT INTO tbl_1
SELECT tbl_2.gateway_id
FROM tbl_2
WHERE tbl_1.classID = tbl_2.class_code
AND tbl_1.departmentID = tbl_2.department_id
But, no luck. I get an error ‘Unknown column tbl_1.classID in WHERE clause’
Should I be using UPDATE or something like that?
Thanks for any help.
I think you are looking for a
UPDATEto update existing rows intbl_1with the correctcategory_idtaken fromtbl_2, not aINSERTwhich will add rows totbl_1