When you use STM.UserID on the join condition, SQL Server immediately looks for a table (or an alias) with the name STM that is in the list of tables you have listed so far in the WHERE clause. It doesn't find any, and hence the error.