Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

ms access - How can i add data from table to other sql

i have 2 department and created new one, i want to update employee departmant but if that employees id equals one of id's listed in other table

Employees

empid  empname  deptname
01     john       dept1
02     bill       dept2
03     alex       dept1
.
.
.
80     tomas      dept1

New_depts_employees_id

empid
02
05
45
18
20
34
78
80
55
32

if employee's id is inside the second table his depname will become 'dept3'

how can i write code make this process in sql language (i using Ms accsess)

question from:https://stackoverflow.com/questions/65935553/how-can-i-add-data-from-table-to-other-sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do you want sql? You can use update and exists as follows:

Update employees
   Set dept_name = 'dept3'
 Where exists (select 1 from New_depts_employees_id n where n.emp_id = employees.emp_id)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...