Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL select unique items from everyone's desk

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

The answer should be

enter image description here

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 )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading