SQL CROSS JOIN or CARTESIAN JOIN

It will return Cartesian Product of sets of rows from the 2 joined table. Here each row of the first table is combined with each row from the second table. Total number of rows present in the final output will be the product of number of rows present in both the tables.

For example PRODUCTS Table has:

product_idproduct_namesupplier_idcategory_idquantity_per_unitprice
1Aniseed Syrup1212 – 550 ml bottles10
2Cajun Seasoning2248 – 6 oz jars22
3Green Tea1110 boxes x 20 bags18
4Gumbo Mix2236 boxes21.35
5Grandmas Boysenberry Spread3212 – 8 oz jars25
6Uncle Bobs Organic Dried Pears3712 – 1 lb pkgs.30
7Northwoods Cranberry Sauce3212 – 12 oz jars40
8Mishi Kobe Niku4618 – 500 g pkgs.97

SUPPLIERS Table has:

supplier_idsupplier_namecontact_nameaddresscitypostal_codecountryphone
1Exotic LiquidsCharlotte Cooper49 Gilbert St.LondonEC1 4SDUK(171) 555-2222
2New Orleans Cajun DelightsShelley BurkeP.O. Box 78934New Orleans70117USA(100) 555-4822
3Grandma Kellys HomesteadRegina Murphy707 Oxford Rd.Ann Arbor48104USA(313) 555-5735
4Tokyo TradersYoshi Nagase9-8 Sekimai Musashino-shiTokyo100Japan(03) 3555-5011
5MayumisMayumi Ohno92 Setsuko Chuo-kuOsaka545Japan(06) 431-7877
6Pavlova, Ltd.Ian Devling74 Rose St. Moonie PondsMelbourne3058Australia(03) 444-2343

Lets execute this cross join query:

SELECT * FROM PRODUCTS CROSS JOIN SUPPLIERS

Its output will be like:

product_idproduct_namesupplier_idcategory_idquantity_per_unitpricesupplier_namecontact_nameaddresscitypostal_codecountryphone
1Aniseed Syrup1212 – 550 ml bottles10Exotic LiquidsCharlotte Cooper49 Gilbert St.LondonEC1 4SDUK(171) 555-2222
1Aniseed Syrup2212 – 550 ml bottles10New Orleans Cajun DelightsShelley BurkeP.O. Box 78934New Orleans70117USA(100) 555-4822
1Aniseed Syrup3212 – 550 ml bottles10Grandma Kellys HomesteadRegina Murphy707 Oxford Rd.Ann Arbor48104USA(313) 555-5735
1Aniseed Syrup4212 – 550 ml bottles10Tokyo TradersYoshi Nagase9-8 Sekimai Musashino-shiTokyo100Japan(03) 3555-5011
1Aniseed Syrup5212 – 550 ml bottles10MayumisMayumi Ohno92 Setsuko Chuo-kuOsaka545Japan(06) 431-7877
1Aniseed Syrup6212 – 550 ml bottles10Pavlova, Ltd.Ian Devling74 Rose St. Moonie PondsMelbourne3058Australia(03) 444-2343
1Aniseed Syrup7212 – 550 ml bottles10Specialty Biscuits, Ltd.Peter Wilson29 Kings WayManchesterM14 GSDUK(161) 555-4448
1Aniseed Syrup8212 – 550 ml bottles10PB Knckebrd ABLars PetersonKaloadagatan 13GteborgS-345 67Sweden031-987 65 43
1Aniseed Syrup9212 – 550 ml bottles10Refrescos Americanas LTDACarlos DiazAv. das Americanas 12.890So Paulo5442Brazil(11) 555 4640

Learn more : SQL Tutorial , SQL Interview Questions