hi
We want all members who selected category 1 as their favorite category to also have category 9 added as one of their favorite categories. I assume the following three queries will ALWAYS produce exactly the same results ( assuming FavCategory.CategoryID and FavCategory.MemberID form a primary key ):
SELECT 9, md1.MemberId FROM MemberDetails AS MD1
INNER JOIN FavCategory as FC1
ON MD1.MemberId = FC1.MemberId
WHERE FC1.CategoryId = 1
AND NOT EXISTS
(SELECT * FROM FavCategory AS FC2
WHERE FC2.MemberId = FC1.MemberId
AND FC2.CategoryId = 9);
SELECT 9, MemberId FROM MemberDetails AS MD1
WHERE EXISTS
(SELECT * FROM FavCategory FC1
WHERE FC1.CategoryId = 1 AND FC1.MemberId = MD1.MemberId
AND NOT EXISTS
(SELECT * FROM FavCategory AS FC2
WHERE FC2.MemberId = FC1.MemberId
AND FC2.CategoryId = 9));
SELECT 9, MemberId FROM MemberDetails AS MD1
WHERE EXISTS
(SELECT * FROM FavCategory FC1
WHERE FC1.CategoryId = 1 AND FC1.MemberId = MD1.MemberId)
AND NOT EXISTS
(SELECT * FROM FavCategory AS FC2
WHERE MD1.MemberId = FC2.MemberId
AND FC2.CategoryId = 9);
thanx