Showing posts with label mysql self join. Show all posts
Showing posts with label mysql self join. Show all posts

Difference between self join and equi join in Mysql

Difference between self join and equi join in Mysql

Self join: Self join is a method of centralizing relational data to a single table.A self-join joins the table to itself.

Self join Example

Equi join: Equi Join is used to combine records from two tables.In equi join we have to use only '=' operator.

Equi Join Example


Bookmark and Share

Self join in Mysql : Mysql Joins

Self join in Mysql:

Self join is a method of centralizing relational data to a single table.A self-join joins the table to itself.

Example:

CREATE TABLE employees (
    NAME VARCHAR(20), 
    email VARCHAR(20),
    mobile VARCHAR(20), 
    sex CHAR(1), 
    birth_date DATE, 
);
     
INSERT INTO  employees VALUES ('xyz','xyz@example.com','11212','F','1985-06-05');
INSERT INTO  employees VALUES ('abc','abc@example.com','11111','M','1985-03-05');
INSERT INTO  employees VALUES ('abc1','abc1@example.com','21111','M','1987-03-05');
         
SELECT e1.name, e2.name,e1.email
FROM employees AS e1, employees AS e2
WHERE e1.email = e2.email AND e1.sex = 'F' AND e2.sex = 'M';


Bookmark and Share