SQL statement with JOIN and WHERE clause
Try the following:
Select e.emp_name from
Employee e inner join Department d
on e.dept_id = d.dept_id
Where d.dept_name in ('HR','Sales');
This query will compare table and dept_id
table . Matching values โโwill be returned. then from all the fields you will select and restrict employees belonging to the department and using the offer .Employee
Department
emp_name
HR
Sales
where
source to share
As long as you want to display employee data, select only this table. The rest is criteria. You want their department to be either "HR" or "Sales", so the direct way of writing this is the IN clause (you can also use the EXISTS clause):
select emp_name
from employee
where dept_id in
(
select dept_id
from department
where dept_name in ('HR', 'Sales')
);
I think this is easier to read than joining tables first and only using them as a filter for another.
source to share