Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple SQL Join Understanding? [duplicate]

Possible Duplicate:
Explicit vs implicit SQL joins
Is there a difference using join andselect from multi-tables?
SQL Joins: Future of the SQL ANSI Standard (where vs join)?

What is the difference between JOIN and declaring multiple tables in the FROM clause?

Such as:

SELECT *
FROM  table1 AS t1,
      table2 AS t2
WHERE t1.id = t2.id

Compared to:

SELECT *
FROM table1 AS t1
INNER JOIN table2 AS t2 ON t2.id = t1.id
like image 967
mawburn Avatar asked Apr 20 '12 14:04

mawburn


People also ask

How to understand joins in SQL Server?

An Easy Way To Understand Joins In SQL Server. Inner join Inner join retrieves all the rows / Records from both the tables which have matching records in both tables. [OR] Inner join is used to retrieve the matching rows/records from more than one table by joining both the tables by using "Join clause" & "on clause".

What is the use of self join in SQL?

SELF JOIN − is used to join a table to itself as if the table were two tables, temporarily renaming at least one table in the SQL statement. CARTESIAN JOIN − returns the Cartesian product of the sets of records from the two or more joined tables.

What is the difference between right join and inner join in SQL?

INNER JOIN − returns rows when there is a match in both tables. LEFT JOIN − returns all rows from the left table, even if there are no matches in the right table. RIGHT JOIN − returns all rows from the right table, even if there are no matches in the left table.

How to join two tables in SQL Server?

In the above Select statement , instead of inner join we can directly use join clause as joins are by default inner join. The above result shows the records which are common in both the tables. Left outer join is used to join both the tables and retrieve all the rows/records from the left table and matching rows/records from the right table.


1 Answers

The second version, with the explicit JOIN and join condition is standardized SQL.

The implicit join syntax with a WHERE clause is deprecated syntax (or, rather, considered bad) - partially because it is easy to forget the WHERE clause and cause a Cartesian product.

like image 195
Oded Avatar answered Sep 21 '22 11:09

Oded