Joins in Dbms
Joins in Dbms
Joins in Dbms
on
Database Management System
by
Mrs. Vrushali A. Patil
Contents of Session
Matched/Common data
INNER JOIN or EQUI JOIN(contd.)
Cust_id cname Loan_id Balance Loan_no cid Branch Amount
1 Max L1 200000 L1 1 Mumbai 1000000
2 Merry L2 180000 L2 2 Bangalore 800000
3 Michle L3 250000 L3 3 Mumbai 1500000
4 Max NULL 300000 Fig.2 borrower Table
Fig.1 Customer Table
• Select cust_id, Loan_id,, Branch, Amount from customer INNER
JOIN borrower ON customer.cust_id=borrower.cid;
customer.cust_id
Cust_id Loan_id Branch Amount
1 L1 Mumbai 1000000
2 L2 Bangalore 8000000
3 L3 Mumbai 1500000
Fig.3 Result Table
NATURAL JOIN
• It generates result based on same attribute name and datatypes.
• Resulting table contains all attributes from both table and only one
copy of a common attribute.
Doctor_id Specialization Cabin Doctor_id Patient Assign_date
D1 Child spec. First floor D1 ABC 2019-03-02
D2 Cardiologist Second floor D2 PQR 2020-05-06
D3 General Physician Ground floor D3 XYZ 2020-04-05
D4 Dentist First floor Fig.2 Patient Table
Fig.1 Doctor Table
Select Roll_no,, Per, Grade from Student, Grade where Per between Lper and Hper;
Select Roll_no,, Per, Grade from Student, Grade where Per>=Lper
Per>= and Per<=Hper;
NON EQUI JOIN(contd.)
JOIN
Roll_no Per Grade
1 62 First Class
2 82 Distinction
3 45 Second Class
4 88 Distinction
5 55 Second Class
6 66 First Class
Select Roll_no, class, Book_id, Bname from Student FULL OUTER JOIN Book ON
Student.Book=Book.Book_id;
FULL OUTER JOIN(contd.)
Roll_no Class Book_id Bname
1 FY B1 Prog. In C
2 FY B2 HTML & CSS
3 SY B3 DBMS Concepts
4 FY B1 Prog. In C
5 TY B3 DBMS Concepts
6 TY NULL NULL
7 FY NULL NULL
NULL NULL B4 Head First Java
NULL NULL B5 MongoDB in Action
Fig.3 Result Table