Non-equi join:
It is the type of inner join which combines the rows from two tables based on the condition. Comparison between the columns of the tables is not based on the equality operator (i.e. not equal to) or not equal sign operator like <,>,<= and >= are seen in the left, right and inner joins. Matching data of the tables are based on an inequality operator rather than equality operator. It is allowing to filter the data of the tables on the basis of range conditions. It is based on the relative values which is satisfied by the tables. It is suitable to retrieve the data based on the range conditions.
It is applicable when one or more columns are using an inequality comparison. It will filter the data on the basis of range. It is used to check the duplicate values. It is used to examine that one value in the one table will fall into another table. It refers to the join condition where the relationship between the columns exits is based on the ON or where clause.
SYNTAX:
SELECT * FROM table1 JOIN table2 ON table1.column_name>=table2.column_name;
In the above syntax, we are joining table1 and table2 because the values in table1.column_name are greater than or equal to the values in table2.column_name. It will return all the rows where this condition is true.
select * from emp JOIN dept ON emp.deptno<dept.deptno
where emp.sal>3000;
In the above query, it will select all the columns from the emp and dept table. The value emp.deptno is less than the dept.deptno and emp.sal is greater than 3000."<" is the join operator instead of equality operator.
select e.*,d.*
from emp e,dept d
where e.sal between 800 and 5000;
Usage:
- It will filter the data on the basis of range & used to filter the emp data based on the range of dept.
- It is used for finding the gaps in the inventory management data when there are no matching orders between the table's customer orders and inventory products.
- It is used to analyze the trends over the time & used to analyze the changes in the product prices over time for the product and customer orders tables.
- It is used for combining the multiple conditions in the single join.
- It is used to check for the duplicate data between the tables.
- It is used to calculate the total data.
Performance:
- It is less efficient than equi join. This is due to requirement of more complex comparison logic.
- Database optimizers find an efficient way to process the queries with large datasets.
- Indexing column is also involved in the joins for improving the performance.
Is it required that the join condition be based on equality?
No, it is not required that the join condition will be based on equality. It depends on the types of joins which you are using and the database system. In the case of natural join, the condition is implicitly based on equality.So,equality is required in natural join. In the case of non-equi join, equality will not be required for the joining condition of the tables. Comparision operators are used like >, <,<= ,>=,!= or <>.
Comments
Post a Comment