Professional Documents
Culture Documents
Joins
Joins
Joins
Joins
1) Define Joins
Joins are operations performed on relational databases to combine rows from two or
more tables based on related columns. Joins allow us to retrieve data from multiple
tables based on the relationships defined between them. By specifying the columns and
conditions for the join, we can create a new result set that includes data from the
combined tables.
a) Inner Join: Returns only the matching rows between two tables based on the join
condition. It combines rows from both tables where the join condition is met.
b) Left Join (or Left Outer Join): Returns all the rows from the left table and the
matching rows from the right table based on the join condition. If there are no
c) Right Join (or Right Outer Join): Returns all the rows from the right table and the
matching rows from the left table based on the join condition. If there are no
d) Full Outer Join: Returns all the rows from both tables, matching rows where the join
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
FROM Customers
ON Customers.CustomerID = Orders.CustomerID;
FROM Orders
ON Orders.CustomerID = Customers.CustomerID;
d) Full Outer Join example:
FROM Customers
ON Customers.CustomerID = Orders.CustomerID;
FROM Customers
Aggregate Functions
Aggregate functions are SQL functions that operate on a set of values and return a single
calculated value. These functions perform calculations across multiple rows and are
column.
a) SUM Example:
FROM Orders;
b) AVG Example:
FROM Products;
c) COUNT Example
FROM Customers;
d) MIN Example
FROM Products;
e) MAX Example
SELECT MAX(Price) AS HighestPrice
FROM Products;
Additional:
The BETWEEN operator is used to select values within a range. It is typically used in the
Example:
The HAVING clause is used in conjunction with the GROUP BY clause to filter the result
set based on aggregated values. It is similar to the WHERE clause, but it operates on the
Example:
FROM Products
GROUP BY Category
The GROUP BY clause is used to group rows in a result set based on one or more
Example:
FROM Products
GROUP BY Category;