Just use the where clause to filter out person A from the resultset. Self join the persons_relationships table on itself, filtering for person A (with the id of x) in one instance, and excluding the same person from the other one: