mysql - INSERT INTO tbl_1 with data from tbl_2 with a WHERE clause -


i need copy data 1 table need use clause in order have work properly.

tbl_1 has classid vendorid category_id (edit: category_id empty, i'm trying copy other table...) , departmentid

tbl_2 has class_code department_id , category_id

i want grab category_id in tbl_2 , put tbl_1 tbl_1.classid = tbl_2.class_code , tbl_1.departmentid = tbl_2.department_id

i tried using:

insert tbl_1 select tbl_2.gateway_id tbl_2 tbl_1.classid = tbl_2.class_code  , tbl_1.departmentid = tbl_2.department_id 

but, no luck. error 'unknown column tbl_1.classid in clause'

should using update or that?

thanks help.

i think looking update update existing rows in tbl_1 correct category_id taken tbl_2, not insert add rows tbl_1

update tbl_1 join tbl_2 on      tbl_1.classid = tbl_2.class_code      , tbl_1.departmentid = tbl_2.department_id set tbl_1.category_id = tbl_2.category_id 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -