Joins: ====== What is a join in SQL? ----------------------- => Join is the process of combining the rows from two or more tables based on a related column. Why Use Join? ------------- => when your data is normalized and spread the data across multiple tables, and to access the data faster join allow s you to pull related data from multiple table using single query. Types of Joins: --------------- => There are five types of joins in SQL: 1) Inner Join 2) Left join 3) Right join 4) Full join 5) Cross Join => Inner join returns only the rows where there is a match in both table. => Left join returns all the rows of the left side table and also returns the rows which are matched from the right side table. If no match found, returns: null => Right join return all rows of the right side table and also returns the rows which are matched in the left side. If no match found, returns: null. => Full join returns all rows when there is a match in one of the tables. Rows without match can return "nulls". => Cross join returns certain row/product of the both tables. How to define the inner join? ----------------------------- Syntax for the inner join: --------------------------- select table-name.column-name1,table-name.colum-name2,... from table-name1 Inner join table-name2 on condition; 1) Create the employee table by using the below syntax: create table employees1101 ( employeeId number, employeename varchar2(50), departmentId number ); 2) Insert the data into the table by using the below syntax: insert into employees1101 values(&employeeId, &employeeName, &departmentId); 3) Create another table named as departments using the below syntax: create table departments ( departmentId number, departmentName varchar2(50) ); 4) Insert the data into above table using below syntax: insert int0 departments values(&departmentId, &departmentName); 5) Requirement is: "getting a list of employees with their department names but only for those who belong to a department (whose department id is matching)". Query: ------ select employees1101.employeeName, departments.departmentName from employees1101 Inner Join departments on employees1101.departmentId = departments.departmentId; Note: ----- While performing the operations on multiple tables, to retrieve the data/field from any specific table we need to use below syntax: table-name.member-name Assignment: ----------- 1) Create a table with the name "student" and add fields like: studentId, studentName, classId 2) Create a table with the name "classes" and add fields like: classId, className 3) insert the data into both the tables. 4) Write a query using SQL inner join to get the names of the students along with the name of the class they are enrolled in, but only for students who are enrolled in an existing class.