How to Join Unrelated SQL Tables
Please read our Disclaimer
Works With
-Microsoft SQL Server 2016 (RTM) – 13.0.1601.5 (X64)
Command:
SELECT d.*, p.* FROM [AdventureWorks2016].[HumanResources].[Department] d JOIN [AdventureWorks2016].[Person].[Person] p ON 1 = 1
Steps and Sample Usage:
- Open and log into your SQL Management Studio
- Open a New Query Windows or (CTRL+N)
- Run the following commands: (Copy and Paste the code block to your Query Window)
SELECT d.DepartmentID, d.Name, p.rowguid, p.FirstName, p.LastName
FROM [AdventureWorks2016].[HumanResources].[Department] d
JOIN [AdventureWorks2016].[Person].[Person] p
ON 1 = 1
WHERE p.rowguid = ‘0AEB5713-8BB0-4B8D-BF81-777158E5FF09’ –filter
- Execute the query by pressing F5.
Use Case:
- You want to export data into a single output.
Caveat:
- The output can be exponentially big and may result to a bottleneck, you must execute with caution.
Sample Data:
-AdventureWorks2016 Database