What is Cross Join ??Why use cross join in SQL
By Rizwan Saqib   Posted on March-28-2018 734
MS Sql Server
Cross Join :
Cross join Produce a Result which is the number of rows in the first table multiplied by rows in the second tableCross joins are used to return every combination of rows from two tables, this sometimes called a Cartesian product.
For Example
There is Two tables
1)Paint
Paint_ID | Paint Name |
1 | Master Paint |
2 | Delux Pant |
Second table Is
2) Colours
Colours_ID | Colour_Name |
1 | Black |
2 | Red |
we want the combination of all colors with paint use Cross join with Colours
Select Paint_ID, Name ,C. Colour_Name From paint
Cross join Colours C
It Give us result like This
Paint_ID | Paint_Name | Colours_Name |
1 | Master Paint | Black |
2 | Deluxe Paint | Black |
3 | Master Paint | Red |
4 | Deluxe Paint | Red |
It show us Combinition of all colours with paint It is called Cross Join and Cartesian
By Rizwansaqib966   28-Mar-2018
Views 734