Either in not both clause in select sql

oracle, sql

Solution

Group them, then calculate the total count for each departments, then filter all departments which has only one location.

SELECT D.DNAME 
FROM DEPARTMENT D 
INNER JOIN DEPTLOC L ON L.DNAME = D.DNAME 
WHERE L.CITY='BOSTON' 
OR L.CITY='DALLAS'
GROUP BY
D.DNAME
HAVING COUNT(1) = 1

Problem

Find the names of all departments located either in BOSTON or in DALLAS" and not in both cities. I having the code like this ``` SELECT D.DNAME FROM DEPARTMENT D INNER JOIN DEPTLOC L ON L.DNAME = D.DNAME WHERE L.CITY='BOSTON' OR L.CITY='DALLAS' ; ``` But this will show the department that located in BOSTON OR DALLAS . But i just want either in, what should i put in order to get the result. Example: in my DEPTLOC TABLE ``` //DEPTLOC DNAME CITY ---------------- ACCOUNTING BOSTON ACCOUNTING DALLAS SALES DALLAS TRANSPORT BOSTON TRANSPORT DALLAS ``` So in my DEPARTMENT i should get output like ``` DNAME ---------- SALES ```

Original source