I have a SQL database: 3 desks, and what they contain
and I need to extract only the items that are unique on each desk and the desk the items are on.
The task looks disturbingly easy but my brain can’t comprehend the extra SQL commands, therefore I have 0 idea how I could get the answer for the question.
A code I created was:
SELECT WhoseDesk, Item, count(Item) as found_nr
FROM [Office]
GROUP BY Item,WhoseDesk
HAVING count(Item)=1
ORDER BY found_nr, WhoseDesk,Item
The answer I got
The answer should be
Ty kind stranger for helping me out.
>Solution :
You can use this query for searching items that are on the desk and not on the other desk:
select *
from [Office] [outer]
where not exists( select 1 from [Office]
where Item = [outer].Item
and WhoseDesk <> [outer].WhoseDesk )

