Learn SQL easily Part - 3 ( SQL JOINS)

SQL JOINS: 

We can combine rows from two or more tables using JOIN. There are basically four types of JOINS.

  1. INNER JOIN
  2. LEFT JOIN
  3. RIGHT JOIN
  4. FULL JOIN
Now we discuss these JOINS.

INNER JOIN:

Suppose we have two tables named student, student_info, and student_personal.

INNER JOIN

The above three tables have a common field that is ID.  We want the id, name,  balance, and home_district of students from the tables above displayed. We just want the records which are common to the tables on the basis of ID.  In the above tables, some ids are similar and the rest are dissimilar.  INNER JOIN is used to combine the similar rows of two or more tables.

SYNTAX:  SELECT table1.column_name, table1.column_name,  table2.column_name, table2.column_name, table3.column_name, table3.column_name 
FROM table1 
INNER JOIN table2 ON  table1.column_name = table2.column_name
INNER JOIN table3 ON  table1.column_name = table3.column_name;

SQL CODE: SELECT  student.id, student.name, student_personal.home_dist, student_info.balance  
FROM student INNER JOIN student_info ON student.id = student_info.id
INNER JOIN student_personal ON  student.id= student_personal.id;




As id 1001, 1003, 1004 are common to both tables so the required information of these ids is displayed for INNER JOIN.

The common field of the three tables

Here A is the common field of the three tables.




0/Post a Comment/Comments