Yep, that's all there is to it. A temp table and a SELECT statement. So let's start breaking this down. First, he creates a temp table that hold the numbers 1 though 5. This is commonly called a Tally table and we've seen it before.

Then he has a SELECT from a SELECT. I'm going to basically rebuild his query from scratch starting at the inside. The simplest piece looks like this:

SELECT a1.n Dane, a2.n English
FROM #n5 a1, #n5 a2

Note that I'm leaving off the part the generates the temp table and populates it. It generates the following result:

Which is 25 rows of possible solutions. He does a cross join of the temp table to itself. This joins each row in the table to every other row in the table -- including itself. If there were nine rows in the table we'd have 81 rows in the result set. His naming of the columns is what maps it back to the problem. In this little sample set we can see every possible permutation of housing for the Dane and the Englishman.

The first piece he adds is a WHERE clause to remove two people living in the same house. Modifying the query we get this:

SELECT a1.n Dane, a2.n English
FROM #n5 a1, #n5 a2
WHERE a2.n NOT IN (a1.n)

The WHERE clause says I want all the possible permutations of this except where the English house (a2.n) is equal to the Danish house (a1.n). This would eliminate all the rows from the above result set where the two numbers are equal.

Let's add a third parameter and see what that looks like.

SELECT a1.n Dane, a2.n English, a3.n German
FROM #n5 a1, #n5 a2, #n5 a3
WHERE a2.n NOT IN (a1.n)
AND a3.n NOT IN (a1.n, a2.n)

which is much easier to read and returns the same result set as above. All that's really left is to add all the possible combinations and fill out the WHERE clause. At that point you get the query at the top of the page.

And that brings us to the suprise. One of the rules from the challenge was that the "green house is on the left side of the white house." I interpreted this to mean next door on the left. You'll notice the WHERE clause in the full query also makes that assumption. There's a line below it that's commented out that has the more general assumption. Switching to the commented out line gives us SEVEN possible solutions.

Removing the CASE and changing the main query to a SELECT * shows us the complete solutions. I can't display them here because they are too wide. I did pick one at random and test it manually against the rules and it came out just fine.

So that's the second solution. Great job Arnold. None of the others were drastically different than these two. If you'd like others to see your solution, please post it in the forums attached to one of these articles and we can all take a look.