Select from Table1, Table2
Table1 (Col1, Col2) with 4 Records
Table2 (Col11, Col22, Col33) with 3 Records
when you use the query given below, It will produce NxM number of rows (Cartesian Join)
select * from table1, table2
The result and column sequence from both tables would be given below with 4 x 3 = 12 Records. Col1,Col2, Col11, Col22, Col33
This is called CROSS JOIN
but using old syntax with ,
in FROM
clause. My advice is not to use old syntax, stick with the JOIN
here.
It produces a cartesian product, so the number of rows in the result set will be the number of rows from table1
multiplied by number of rows from table2
(assuming there are no constraints in the WHERE
clause). It effectively pairs each row from table1
with a row coming from table2
.
Below query is an equivalent but does explicit JOIN
operation which separates constraint logic of data retrieval (normally put within the WHERE
clause) from logic of connecting related data stored across separate tables (within the FROM
clause):
SELECT *
FROM table1
CROSS JOIN table2
Consider an example where table1
has 8 rows and table2
has 5 rows. In the output, you get 40 rows (8 rows * 5 rows), because it pairs all rows from both sources (tables).
You will get all rows from table1 multiplied by all rows from table2, and will display depending on the columns of both tables. As @sgeddes pointed out, creating a cartesian product.