JOIN IN MYSQL




 JOIN

A JOIN is a query through which we can extract queries from two or more tables. It means, it combines rows from two or more tables. Rows in one table can be joined to rows in another table according to common values existing in corresponding columns.

e.g. 
SELECT * FROM CUSTOMER, SUPPLIER;


EQUI-JOIN
In an EQUI-JOIN operation, the values in the columns are being joined and compared for equality. All the columns in the tables being joined are included in the results, e.g. Two tables EMPLOYEES and DEPARTMENTS are given below:
Class 12 Informatics Practices Notes Chapter 11 SQL Functions and Table Joins 6

Class 12 Informatics Practices Notes Chapter 11 SQL Functions and Table Joins 7

SELECT EMPLOYEES.Employee_id, DEPARTMENTS.Department_name
FROM EMPLOYEES, DEPARTMENTS
WHERE EMPLOYEES. Department_id = DEPARTMENTS. Department_Id;

Non-Equi Join
A non-equi join is a join condition containing something other than an equality operator
SELECT e.Last_name, j.GRA FROM EMPLOYEES e, JOELGRADES j
WHERE e.SALARY BETWEEN j.LOWEST_SAL AND j.HIGHEST SAL;

 Natural Join


Usually the result of an equi-join contains two identical columns. Here by restarting the query, we can eliminate one of the two identical columns. It is known as Natural Join.
We can also join two tables using the natural join using NATURAL JOIN clause.

SELECT * FROM <tablel> NATURAL JOIN <table2>; e.g. there are two given tables FOOD and COMPANY:



Post a Comment

0 Comments