Thanks visakh, I've popped together the following script, by my reconing it should produce the matches below:--The table that holds the Au Pair's languagesCREATE TABLE #AuPair( AuPairId int, PrimaryLanguage int, Age tinyint, Height tinyint, Smoker bit )--The table that holds the Family's languagesCREATE TABLE #Family( FamilyId int, PrimaryLanguage int, MinAge tinyint, MaxAge tinyint, MinHeight tinyint, MaxHeight tinyint, Smoker tinyint -- 0 = No, 1 = Yes, 2 = Either)--The table that holds the other languages the Au Pair can speakCREATE TABLE #AuPairLanguage( AuPairId int, LanguageId int)--The table that holds the languages the Family would likeCREATE TABLE #FamilyLanguage( FamilyId int, LanguageId int)--Insert the dummy dataINSERT INTO #AuPair (AuPairId, PrimaryLanguage, Age, Height, Smoker)SELECT 1, 3, 30, 115, 0 UNION ALL SELECT 2, 3, 19, 100, 0 UNION ALL SELECT 3, 4, 22, 135, 1INSERT INTO #Family (FamilyId, PrimaryLanguage, MinAge, MaxAge, MinHeight, MaxHeight, Smoker)SELECT 1, 1, 0, 255, 100, 130, 0 UNION ALL SELECT 2, 2, 20, 25, 0, 255, 2 UNION ALL SELECT 3, 2, 0, 255, 0, 255, 1INSERT INTO #AuPairLanguage (AuPairId, LanguageId)SELECT 1, 1 UNION ALL SELECT 1, 2 UNION ALL SELECT 2, 1 UNION ALL SELECT 2, 2 UNION ALL SELECT 3, 2INSERT INTO #FamilyLanguage (FamilyId, LanguageId)SELECT 2, 3 UNION ALL SELECT 3, 1DROP TABLE #AuPairDROP TABLE #FamilyDROP TABLE #UserInterestsDROP TABLE #FamilyLanguage
Family 1--------------Aupair 1 : Match (matches all and primary/secondary languages)Aupair 2 : No Match (doesn't speak any of the languages)Aupair 3 : No Match (too tall)Family 2--------------Aupair 1 : No Match (too old)Aupair 2 : No Match (too young)Aupair 3 : MatchFamily 3--------------Aupair 1 : No Match (not a smoker)Aupair 2 : No Match (not a smoker)Aupair 3 : MatchIs that what you were after? (This is a cut down version to try and keep things simple).Tim----------------------------I've finally started blogging (all be it badly!)Check it out:http://blogs.thesitedoctor.co.uk/tim/