Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created January 27, 2016 09:03
Show Gist options
  • Save dnasca/2cd6b7fcbc341ad0a183 to your computer and use it in GitHub Desktop.
Save dnasca/2cd6b7fcbc341ad0a183 to your computer and use it in GitHub Desktop.
Cross Joins - cross-product of two data sources, aka a Cartesian product. Each row from a data source is matched with ALL rows in the other data source. (DataSource1 * DataSource2)
--how many rows?
SELECT COUNT(*)
FROM HumanResources.Employee;
--what gets returned?
SELECT e.BusinessEntityId, edh.DepartmentId
FROM HumanResources.Employee AS e
CROSS JOIN HumanREsources.EmployeeDepartmentHistory AS edh;
--practical use?
SELECT TOP 100000
ROW_NUMBER() OVER (ORDER BY sv1.number) AS num
FROM [master].[dbo].[spt_values] AS sv1
CROSS JOIN [master].[dbo].[spt_values] AS sv2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment