Basic SQL Joins

Basic Joins in SQL

Generally, tables are related to each other using Foreign Key constraints. Joins in SQL combines records from two related tables to retrieve the data

Different types of Joins

inner-join-vs-cross-join-in-sql-server

Inner Join or Join: Returns only the matching rows from both the tables

Outer Join: Outer Joins are of 3 types

Full Outer Join or Full Join: Returns all the rows, including non-matching rows from both left and right tables.

Left Outer Join or Left Join: Returns all the rows from the left table and only matching rows from the right.

Right Outer Join or Right Join: Returns all the rows from the right table and only matching rows from the left.

Cross Join: Cross Join selects all the rows from the first table and all the rows from the second table that does not have a WHERE clause produces Cartesian product i.e. with all possibilities. In simple words, Cross Join creates all possible combination of records irrespective of a table being related or not. Cross Join shouldn’t have ON clause

General Syntax for Joins

SELECT column_name

FROM left_table_name

JOIN_TYPE right_table_name

ON Join_condition

 

 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s