This was done in a single script, but not a single query.
The insert into the #temp table is executed as a seperate query.
You would need to start with the use of a WITH table statement, or a derived table to get this done to a single query.
Interesting way to resolve a bad table design issue without correcting the bad table design.
Maybe I'm wrong, but I think all of the #temp table stuff was just to have sample data to show how the technique works. He could have just written something like:
Delete T From
(Select Row_Number() Over(Partition By [fld1],[fld2],[fld3],[fld4] order By [fld1]) As RowNumber,* From [tablename])T
Where T.RowNumber > 1
and then explained that the partition clause needs to include all of the fields. Instead, he included a concrete example.