If you are going to post solutions to 2-year-old-resolved questions then it is a really good idea to point out why your solution is better than those already offered. Rather than just dumping some code that looks remarkably similar to Solution 1.
Does this even work? "table1.id" is not the same as "table1.ID"