Blog

Cross Join in SQL

SQL

Cross Join in SQL

In SQL, 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.

Where to use CROSS JOIN?

Suppose, we have two database tables: Cars, listing car models and their prices, and Colors, listing color names and extra prices for those colors. We need to get all possible combinations of cars and colors.

Below is the CAR table

Below is the COLOR table

So to get the all possible combinations, we will have to run the following CROSS JOIN

				
					SELECT * FROM CAR CROSS JOIN COLOR
				
			

Now we will get the following results, which will list out all the combinations of the CARS with the COLORS.

Please comment and share if you like this post and tell us about how we can enhance our posts in dotnetcoaching. Thanks.

Subhajit

Comments (2)

  1. Praveen

    I m interested

    1. Contact me at 9874634054/9073956822

Comments are closed.