Difference between a theta join, equijoin and natural join

后端 未结 7 620
眼角桃花
眼角桃花 2020-11-29 17:20

I\'m having trouble understanding relational algebra when it comes to theta joins, equijoins and natural joins. Could someone please help me better understand it? If I use t

7条回答
  •  鱼传尺愫
    2020-11-29 17:46

    Theta Join: When you make a query for join using any operator,(e.g., =, <, >, >= etc.), then that join query comes under Theta join.

    Equi Join: When you make a query for join using equality operator only, then that join query comes under Equi join.

    Example:

    > SELECT * FROM Emp JOIN Dept ON Emp.DeptID = Dept.DeptID;
    > SELECT * FROM Emp INNER JOIN Dept USING(DeptID)
    
    This will show:
     _________________________________________________
    | Emp.Name | Emp.DeptID | Dept.Name | Dept.DeptID |
    |          |            |           |             |
    

    Note: Equi join is also a theta join!

    Natural Join: a type of Equi Join which occurs implicitly by comparing all the same names columns in both tables.

    Note: here, the join result has only one column for each pair of same named columns.

    Example

     SELECT * FROM Emp NATURAL JOIN Dept
    This will show:
     _______________________________
    | DeptID | Emp.Name | Dept.Name |
    |        |          |           |
    

提交回复
热议问题