CELKO (8/21/2014)
This is one of those places where a loop (please see the solution I posted above) actually does work quite well and it's self correcting based on the number of rows in the two tables. And, remember... I'm one of those that hates loops! 😉
We are getting into an example of why "set-oriented programming can stink" that us RDBMS (functional, declarative, whatever) do not want to admit. By its nature, set-oriented programming must produce all valid answers.
That can be a very large set 🙁 An unusably large set. And it the real world we need only one answer to move forward. It does not matter which one, really.
Remember stable marriages problem? At least one solution must exist. Solutions can favor men or women various degrees. So pick one 😉
🙂
--Jeff Moden
Change is inevitable... Change for the better is not.