SQL Cartesian or Cross Joins: Syntax
SQL Cartesian or Cross Joins: Syntax
T he CART ESIAN J O IN or CRO SS J O IN returns the Cartesian product of the sets of records from the
two or more joined tables. T hus, it equates to an inner join where the join-condition always evaluates to T rue or
where the join-condition is absent from the statement.
Syntax:
T he basic syntax of INNER J O IN is as follows:
SELECT table1.column1, table2.column2...
FROM table1, table2 [, table3 ]
Example:
Consider the following two tables, (a) CUST OMERS table is as follows:
+----+----------+-----+-----------+----------+
| ID | NAME
| AGE | ADDRESS
| SALARY
|
+----+----------+-----+-----------+----------+
| 1 | Ramesh
| 32 | Ahmedabad | 2000.00 |
| 2 | Khilan
| 25 | Delhi
| 1500.00 |
| 3 | kaushik | 23 | Kota
| 2000.00 |
| 4 | Chaitali | 25 | Mumbai
| 6500.00 |
| 5 | Hardik
| 27 | Bhopal
| 8500.00 |
| 6 | Komal
| 22 | MP
| 4500.00 |
| 7 | Muffy
| 24 | Indore
| 10000.00 |
+----+----------+-----+-----------+----------+
Now, let us join these two tables using INNER JOIN as follows:
SQL> SELECT ID, NAME, AMOUNT, DATE
FROM CUSTOMERS, ORDERS;
| 4 | Chaitali |
1500 | 2009-10-08 00:00:00 |
| 4 | Chaitali |
1560 | 2009-11-20 00:00:00 |
| 4 | Chaitali |
2060 | 2008-05-20 00:00:00 |
| 5 | Hardik
|
3000 | 2009-10-08 00:00:00 |
| 5 | Hardik
|
1500 | 2009-10-08 00:00:00 |
| 5 | Hardik
|
1560 | 2009-11-20 00:00:00 |
| 5 | Hardik
|
2060 | 2008-05-20 00:00:00 |
| 6 | Komal
|
3000 | 2009-10-08 00:00:00 |
| 6 | Komal
|
1500 | 2009-10-08 00:00:00 |
| 6 | Komal
|
1560 | 2009-11-20 00:00:00 |
| 6 | Komal
|
2060 | 2008-05-20 00:00:00 |
| 7 | Muffy
|
3000 | 2009-10-08 00:00:00 |
| 7 | Muffy
|
1500 | 2009-10-08 00:00:00 |
| 7 | Muffy
|
1560 | 2009-11-20 00:00:00 |
| 7 | Muffy
|
2060 | 2008-05-20 00:00:00 |
+----+----------+--------+---------------------+