How to check for mutual existence of Fields in same table in Two columns
Posted
by ranabra
on Stack Overflow
See other posts from Stack Overflow
or by ranabra
Published on 2010-03-14T22:41:38Z
Indexed on
2010/03/14
22:45 UTC
Read the original article
Hit count: 415
I tried using "Exist" and "IN". Not only did I not succeed, it didn't seem as an efficient solution.
Here is a simplified example:
TblMyTable
WorkerUserName - WorkerDegree - ManagerUserName - ManagerDegree
I need a query where there is a mutual connection / existence.
What I mean is only where the worker, ex. "John" has a manager named "Mary", and where Mary the manager has a worker named "John".
John the worker can have several managers and Mary the manager can have several workers.
So the result will be (the order doesn't matter) ideally in one line:
John - BSc -- Mary - M.A.
or
Mary - M.A. -- John - BSc
The punchline is it's only one table. it is not really managers and workers, this is just a simplification of the situation.
In the real situation both are equal, in a Table of names of users working with other users. Database is SQL 2005.
Many thanx in advance
© Stack Overflow or respective owner