Collection of methods to generate random string in a single SQL statement
M1: Recursive string concatenation
On SQL Server the method is limited by 100 characters because of CTE recursion level limitation. The method has the performance issues when using in loops/joins because the table always have 100 rows generated every time.
Better to see once than to hear a hundred times. This small article explains what are the different kinds of joins in SQL.
At the first time you should take into account that SQL is a declarative 4th generation language. So the best way to use it (especially for beginners) is to write the query and let SQL optimizer do its job. That means thinking in set-oriented terms and avoiding sub-queries.
Let's take two example tables: Companies and Contacts.