I have this table in my database where HusbandPersonId
and WifePersonId
are foreign keys to another table called Person
, and the start/end date refer when the marriage start and when it ends.
And I have this query :
SELECT
DISTINCT A.WifePersonId
FROM
Couple A
INNER JOIN Couple B
ON A.WifePersonId = B.WifePersonId
AND A.HusbandPersonId <> B.HusbandPersonId
AND A.StartDate < B.EndDate
AND A.EndDate > B.StartDate;
which returns any wife that is married to more than one person at same time.
Now I would like to add an index to improve the speed of search of this query.
Which index would be the best and what is the execution plan of the query before and after the index has been added ?
This is a request in homework and I search too much but I didn't find any helpful topic
Can anyone help on this ?