What is use of cross-join in Sql
Loading
What is use of cross-join in Sql
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal YelvePosted Oct 13, 2022, 5:27 AM
CROSS JOIN, produces the cartesian product of the 2 tables involved in the join. For example, in the Employees table, we have 10 rows and in the Departments table, we have 4 rows. So, a cross join between these 2 tables produces 40 rows. Cross Join shouldn't have an ON clause.
Another Example
Consider you have a Car table that holds model information Car(Make, Model) and AvaliableColorOption(Color)
All available car options can be achieved by cross-join.
Car table:
1. Benz C-Class
2. Benz S-Class
AvaliableColorOption:
1. Red
2. Green
The Cartesian Product of the tables will yield:
1. Benz C-Class Red
2. Benz S-Class Red
3. Benz C-Class Green
4. Benz S-Class Green
Brahma Prakash ShuklaPosted Oct 19, 2022, 11:38 AM
CROSS JOINs are used to combine each row of one table with each row of another table, and return the Cartesian product of the sets of rows from the tables that are joined.
Rajanikant HawaldarPosted Oct 13, 2022, 8:42 AM
https://www.c-sharpcorner.com/blogs/cross-join-in-sql
https://www.c-sharpcorner.com/UploadFile/ff0d0f/joins-in-sql-server/
https://www.c-sharpcorner.com/UploadFile/219d4d/joins-in-sql-server/
Amit MohantyPosted Oct 13, 2022, 5:07 AM
The CROSS JOIN is used to generate a paired combination of each row of the first table with each row of the second table.
It is useful when you need all combinations. It maps each row of the first table with all the rows from the second table.
For more details check the links.
https://stackoverflow.com/questions/219716/what-are-the-uses-for-cross-join
https://www.scaler.com/topics/cross-join-in-sql/