SQL Tutorials for beginners: SQL Join Types

preview_player
Показать описание
SQL JOIN: A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
The INNER JOIN query is used to retrieve the matching records from two or more tables based on the specified condition. SQL Server follows the SQL stadards for inner join queries.
The LEFT JOIN is a type of inner join where it returns all the records from the left table and matching records from the right table. Here, the left table is a table that comes to the left side or before the "LEFT JOIN" phrase in the query, and the right table refers to a table that comes at the right side or after the "LEFT JOIN" phrase. It returns NULL for all non-matching records from the right table.
The RIGHT JOIN is the reverse of LEFT JOIN. The RIGHT JOIN query returns all the records from the right table and matching records from the left table.

Here, the right side table is a table that comes to the right side or after the "RIGHT JOIN" phrase in the query, and the left table is a table that comes at the left side or before the "RIGHT JOIN" phrase.

The RIGHT JOIN returns NULL for all non-matching records from the left table. In some databases, it is called RIGHT OUTER JOIN.
The FULL JOIN returns all the records all the specified tables. It includes NULL for any non-matching records.

In some databases, FULL JOIN is called FULL OUTER JOIN. It can return a very large result set because it returns all the rows from all the tables.
In SQL Server, the self-join is like a regular join, but it joins a table to itself. Similar to any other join, a self-join requires at least two tables. But instead of adding a different table to the join, you add another instance of the same table. It is a join between two copies of the same table. Self-join is mainly used for querying the hierarchical data stored in a single table.

There is no Self Join keyword. You write a normal join where both the tables involved in the join are the same.

#sql #sqlqueries #sqltutorialforbeginners #sqlserver #sql_server #sqltutorials #sqltutorial #sqljoins #join #innerjoin #selfjoin
#leftjoin #rightjoin #fulljoin #crossjoin
Рекомендации по теме