Select users belonging only to particular departments

后端 未结 12 2281
挽巷
挽巷 2021-02-18 12:49

I have the following table with two fields namely a and b as shown below:

create table employe
(
    empID varchar(10),
    department varchar(10)
);
         


        
12条回答
  •  难免孤独
    2021-02-18 13:34

    What about a self join? (ANSI Compliant - worked for 20+ years)

    SELECT * FROM employee e JOIN employee e2 ON e.empid = e2.empid
    WHERE e.department = 'x' AND e2.department ='y'
    

    This shows that a101 and a104 both work in both departments.

提交回复
热议问题