Combine Tables Archives
There are many ways you can combine tables together.
This page is a collection of articles going over set operators, joins, sub queries, and common table expressions. All are great techniques you can learn today:
Use set operators when you wish to combine rows from separate tables together.
Joins come in handy when you want to combine columns from two or more tables. Use joins to combine columns from two, three, or more tables. Also, learn the different way joins can match data and influence which row are included in your result.
I love using subqueries to avoid hard coding values in my where clause. Once you get good with subqueries, you’ll see there are a great way to avoid “hard-coding” specific values into your queries.
Finally, when you combine tables together, your statements can get real funky and unmanageable. Use Common Table Expressions to make the more readable!
All the examples for this lesson are based on Microsoft SQL Server Management Studio and the sample databases AdventureWorks and WideWorldImporters. You can get started using these free tools using my guide Getting Started Using SQL Server.