Thursday, January 31, 2019

SQL - Joins


SQL Joins Tutorial for Beginners - Inner Join, Left Join, Right Join, Full Outer Join


SQL JOIN


Different Types of SQL JOINs

Here are the different types of the JOINs in SQL:
  • (INNER) JOIN: Returns records that have matching values in both tables
  • LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table
  • RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table
  • FULL (OUTER) JOIN: Return all records when there is a match in either left or right table



Inner vs Outer Joins on a Many-To-Many Relationship


Recipes                                recipe_ingredients                    ingredients

Id - int                                  recipe_id - int                           id - int
name-varchar(400)              ingredient_id - int                     item - varchar(4000)
description - text
category_id - int
chef_id-int
created-datetime

categories                             chefs

id - int                                   id-int
name - varchar(255)             name - varchar(255)


"many-to-many":

Each recipe - linked to ingredients (dish)
each ingredient - in many dishes


No comments:

Post a Comment