0% found this document useful (0 votes)
13 views3 pages

Advance SQL For Processing Multiple Tables

The document outlines advanced SQL techniques for processing multiple tables, focusing on various types of joins: INNER JOIN, FULL JOIN, LEFT JOIN, and RIGHT JOIN, along with their usage in SQL queries. It includes laboratory exercises to create a database with two tables (Courses and Students) and provides SQL examples for each join type. The results of these queries demonstrate how to retrieve matched and unmatched records from the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Advance SQL For Processing Multiple Tables

The document outlines advanced SQL techniques for processing multiple tables, focusing on various types of joins: INNER JOIN, FULL JOIN, LEFT JOIN, and RIGHT JOIN, along with their usage in SQL queries. It includes laboratory exercises to create a database with two tables (Courses and Students) and provides SQL examples for each join type. The results of these queries demonstrate how to retrieve matched and unmatched records from the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ADVANCE SQL FOR PROCESSING MULTIPLE TABLES

1. INNER JOIN
An INNER JOIN returns only the rows where there is a match in both tables based on the
specified condition.

2. FULL JOIN
A FULL JOIN returns all records when there is a match in either the left or right table. If
there’s no match, it returns NULL for columns from the table with no match.

3. FULL JOIN with WHERE CLAUSE

4. LEFT JOIN
A LEFT JOIN returns all records from the left table (in this case, Students), and the
matched records from the right table (Courses). If there’s no match, NULL is returned for
columns from the right table.

5. LEFT JOIN with WHERE CLAUSE

6. RIGHT JOIN
A RIGHT JOIN returns all records from the right table, and the matched records from the
left table. If there’s no match, NULL is returned for columns from the left table.

7. RIGHT JOIN with WHERE CLAUSE

Laboratory Exercises:
 Create a database with two tables.
 Name table 1 as Courses with columns: course_id (interger, primary key), course_name
 In Courses table add 6 courses BSIT, BEED, BSED, BSBA-HRM, BSBA-MM, BSOA
 Name table 2 as Students wth columns: student_id (integer, primary key), student_name,
course_id (integer)
 In the Students table add 20 students: 4 students without course_id, 4 students each
BSIT, BEED, BSOA, BSED.
Perform:
1. Inner Join
SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
INNER JOIN Courses
ON Students.course_id = Courses.course_id;

2. Full Join
SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
FULL JOIN Courses
ON Students.course_id = Courses.course_id;

3. Full Join with Where Clause


SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
FULL JOIN Courses
ON Students.course_id = Courses.course_id
WHERE Students.course_id IS NULL OR Courses.course_id IS NULL;

4. Left Join
SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
LEFT JOIN Courses
ON Students.course_id = Courses.course_id;

5. Left Join with Where Clause


SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
LEFT JOIN Courses
ON Students.course_id = Courses.course_id
WHERE Courses.course_id IS NULL;

6. Right Join
SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
RIGHT JOIN Courses
ON Students.course_id = Courses.course_id;

7. Right Join with Where Clause


SELECT Students.student_id, Students.student_name, Courses.course_id, Courses.course_name
FROM Students
RIGHT JOIN Courses
ON Students.course_id = Courses.course_id
WHERE Students.student_id IS NULL;

Results:
1. You’ll see a list of students who are enrolled in a course, along with the course details.
2. You’ll see a list of all records where there is a match in either Students or Courses, and
also includes unmatched rows with NULLs in the columns that don’t have a match
3. You’ll see students without a course or courses without any students.
4. You’ll see a list of all students, with their course details if available. For students without
a course, the course_id and course_name fields will be NULL.
5. You’ll see a list of students who are not enrolled in any course.
6. You’ll see a list of all courses, with student details if available. Courses without any
students will have NULL values in the student_id and student_name fields.
7. You’ll see a list of courses that do not have any students enrolled.

You might also like