0% found this document useful (0 votes)
17 views

Database Systems Lab 7 Presentation

This document discusses SQL joins, including inner joins, joins with an ON clause, and joining multiple tables. It provides examples of different types of joins and exercises for students to practice joins. Key concepts covered include using joins to combine rows from different tables based on related columns, SQL aliases to give tables temporary names, and joining more than two tables through multiple join operations.

Uploaded by

sp22-bse-097
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Database Systems Lab 7 Presentation

This document discusses SQL joins, including inner joins, joins with an ON clause, and joining multiple tables. It provides examples of different types of joins and exercises for students to practice joins. Key concepts covered include using joins to combine rows from different tables based on related columns, SQL aliases to give tables temporary names, and joining more than two tables through multiple join operations.

Uploaded by

sp22-bse-097
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

LAB 7: SQL JOINS AND

WHERE CLAUSE
• Objective: Understand the concepts of joining tables in SQL.
Explore the use of WHERE clause in conjunction with joins and
get hands-on experience with various types of joins.
SQL JOINS
• Joins are used to combine rows from two or more tables based on a
related column between them.
EXAMPLE: SQL JOIN
WITH WHERE CLAUSE
• SELECT Students.Name, Courses.CourseName FROM Students,
Courses WHERE Students.CourseID = Courses.ID;
EXERCISE: SQL JOIN
WITH WHERE CLAUSE
• Retrieve the names of students and the names of the courses they
are enrolled in, using the 'Students' and 'Courses' tables.
SQL JOIN WITH ON
CLAUSE
• The ON clause is used to specify a join condition. It determines
which records should be joined.
EXAMPLE: JOIN & ON
• SELECT Students.Name, Courses.CourseName FROM Students
JOIN Courses ON Students.CourseID = Courses.ID;
EXERCISE: JOIN & ON
• List the products and their respective suppliers, using the 'Products'
and 'Suppliers' tables.
SQL INNER JOIN
• The INNER JOIN keyword selects records that have matching
values in both tables.
EXAMPLE: INNER JOIN
• SELECT Students.Name, Courses.CourseName FROM Students
INNER JOIN Courses ON Students.CourseID = Courses.ID;
EXERCISE: INNER JOIN
• Retrieve the order details and corresponding customer details using
the 'Orders' and 'Customers' tables.
SQL ALIAS FOR TABLE
NAMES
• SQL aliases are used to give a table or a column a temporary name.
It makes column names more readable.
EXAMPLE: ALIAS FOR
TABLE NAMES
• SELECT s.Name, c.CourseName FROM Students AS s, Courses
AS c WHERE s.CourseID = c.ID;
EXERCISE: ALIAS FOR
TABLE NAMES
• Use aliases 'p' for 'Products' table and 's' for 'Suppliers' table and
list product names with their suppliers.
SQL JOINING TWO
TABLES
• Joining two tables fetches data from both tables, but only for the
rows where there is a match in both tables.
EXAMPLE: JOINING TWO
TABLES
• SELECT s.Name, e.CourseName FROM Students s JOIN
Enrollment e ON s.StudentID = e.StudentID;
EXERCISE: JOINING TWO
TABLES
• Join the 'Orders' and 'Products' tables to list all orders along with
the ordered product names.
SQL JOINING THREE OR
MORE TABLES
• Multiple JOIN operations can be used to join more than two tables.
EXAMPLE: JOINING
THREE TABLES
• SELECT s.Name, e.CourseName, t.TeacherName FROM Students
s JOIN Enrollment e ON s.StudentID = e.StudentID JOIN Teachers
t ON e.TeacherID = t.TeacherID;
EXERCISE: JOINING
THREE TABLES
• Join 'Orders', 'Products', and 'Customers' tables to retrieve orders,
product names, and customer details for each order.
UNDERSTANDING SQL
JOINS
• Mastering SQL joins is critical for retrieving data spread across
multiple tables effectively. It allows for flexible and powerful data
analysis.
FEEDBACK AND
QUESTIONS
• Students are encouraged to provide feedback and ask questions at
the end of the lab.

You might also like