Posts

Showing posts with the label union-all

What is CROSS JOIN (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION…)

What is CROSS JOIN (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION…) I came across an odd bit of legacy code while going back through old code for cleanup, and I'm trying to pin down exactly what it does... CROSS JOIN (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) as b It's a technique I haven't seen before, including multiple union selects of numbers inside a cross join, and I'm honestly really confused about what it's doing and why someone would do it. Possible duplicate of SQL Server: What is the difference between CROSS JOIN and FULL OUTER JOIN? – Alessandro Da Rugna Jun 30 at 23:31 1 Answer 1 Cross join creates a Cartesian product. Cross join Assuming the from clause looks like: from FROM t ...