I found the following query and appreciate it if someone can help explain to me what this means.
select * from table1, table2
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 .
A VIEW in SQL Server is like a virtual table that contains data from one or multiple tables. It does not hold any data and does not exist physically in the database. Similar to a SQL table, the view name should be unique in a database. It contains a set of predefined SQL queries to fetch data from the database.
Note: The FULL OUTER JOIN keyword returns all matching records from both tables whether the other table matches or not. So, if there are rows in "Customers" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Customers", those rows will be listed as well.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With