![]() |
VOOZH | about |
DBMS or Database Management Systems consist of data collected from various sources. Database administrators and analysts use this data to analyze the collected data. Database administrators execute the query through which some output is generated, the conditions are passed through the query. This query can vary from simple to complex query. Joins in a database management system is the concept where the data is been retrieved from more than two tables.
So there is the advanced concept of the database management system which is Conditional Join, which is helpful for database administrators to define the custom query or the complex query having various functions like aggregation functions comparison operators, logical operators, etc. So in this article, we will understand the concept of conditional join. We will see the uses of conditional join. Later we will understand the concept through a simple example.
Conditional Join in DBMS is the concept where the database administrators have the provision to design a complex query, which includes conditions, including aggregative functions that can return some values, or which can perform mathematical calculations, These conditional joins also allow various types of operators to be used in the query, like logical orbitals, comparison operators, etc.
Below mentioned are the operators that are used in the conditional join.
Comparison operators are used to compare Values and are used to specify conditions in the where clause of the conditional join query.
Logical operators in Conditional Join are used to combine multiple conditions.
Aggregation functions in conditional join are used to perform mathematical calculations on the subsets of records that meet the specific condition. It summarised the data and returns a single value for each group of rows.
Let us understand the Conditional Join concept using an example.
Consider the below tables (Orders and OrderItems).
Table 1: Order_Data Table
| OrderID | CustomerID | OrderDate |
|---|---|---|
| 1 | 101 | 2023-07-15 |
| 2 | 102 | 2023-07-16 |
| 3 | 103 | 2023-07-17 |
| 4 | 104 | 2023-07-18 |
| 5 | 105 | 2023-07-159 |
Table 2: Items_Data Table
| OrderItemID | OrderID | ProductID | Quantity |
|---|---|---|---|
| 1 | 1 | 101 | 3 |
| 2 | 2 | 102 | 5 |
| 3 | 3 | 103 | 2 |
| 4 | 1 | 102 | 2 |
| 5 | 2 | 103 | 4 |
SELECT o.CustomerID, SUM(oi.Quantity) AS TotalQuantitySell
FROM Orders_Data o
INNER JOIN Items_Data oi ON o.OrderID = oi.OrderID
WHERE o.OrderDate > '2023-07-16'
GROUP BY o.CustomerID;
| CustomerID | TotalQuantitySell |
|---|---|
| 102 | 9 |
| 103 | 6 |
Explanation: In the above example, we have got the result, where we used the comparison operator in the where clause of the query. Along, with this, we have also used the SUM function that calculates the total value of items sold for the individual customer.