T-SQL 101: 137 Inserting rows with data from another SQL Server table
When you’re performing an INSERT, you can also get values from a query., rather than specifying the values in the INSERT statement.
In the example shown above, I’ve queried for a distinct list of order contacts and their phone number from the dbo.Orders table. I’m then inserting those values into the dbo.OrderContacts table.
These types of statements are easy to debug because I can just highlight the SELECT clause and run it to see what comes back.
2025-03-30