You might want to look at the book "The Stable Marriage Problem." By Dan Gisfield and Robert W. Irving. (ISBN-10 02620171185) MIT press. I also posted a solution to this problem in SQL several years ago. .
Look at my book, "Joe Celko's SQL Puzzles and Answers (second edition)" when we discussed this in detail in puzzle #67. The important thing to remember about this problem is that there's always a solution but often more than one solution. Some solutions favor the husbands, while others favored the wives. The question is, at a higher level, whose happiness do you want to maximize?
Please post DDL and follow ANSI/ISO standards when asking for help.