Lakshmi Preya Lakshmi Preya - 1 month ago 11
SQL Question

SQL query for returning rows from two tables

Can anyone explain me how this query is working. Thanks in advance.

image1

Answer

That query is used for returning a cartesian product (https://en.wikipedia.org/wiki/Cartesian_product) of both tables.

In this case 100 x 0 equals to 0 rows in total. Similarly 100 x 10 would equal to 1K rows.

The query itself can also be written with:

SELECT Tbl1.* FROM Tbl1 CROSS JOIN Tbl2;

OR

SELECT Tbl1.* FROM Tbl1 INNER JOIN Tbl2 ON 1 = 1;
Comments