Difference between revisions of "PostgreSQL-Database/C2/JOIN-and-INNER-JOIN-Clause/English"
| Line 20: | Line 20: | ||
|| In this tutorial, we will learn about, | || In this tutorial, we will learn about, | ||
| − | * '''JOIN | + | * '''JOIN clause''' |
| − | * '''INNER JOIN | + | * '''INNER JOIN clause''' and |
* How to combine data from two related tables. | * How to combine data from two related tables. | ||
| Line 54: | Line 54: | ||
The following '''code file''' is required to practice this tutorial. | The following '''code file''' is required to practice this tutorial. | ||
| − | • ''' | + | • '''jc-commands.txt''' |
This file is provided in the '''Code Files''' link on this tutorial page. | This file is provided in the '''Code Files''' link on this tutorial page. | ||
| Line 93: | Line 93: | ||
|| This is the syntax of the '''Joins clause.''' | || This is the syntax of the '''Joins clause.''' | ||
| − | '''SELECT column_names | + | '''SELECT column_names''', specifies which columns to display. |
'''FROM table1''' takes data from the first table. | '''FROM table1''' takes data from the first table. | ||
| Line 112: | Line 112: | ||
|- | |- | ||
| − | || | + | || Showing Student table. |
| − | + | ||
|| Let us create another table named '''results'''. | || Let us create another table named '''results'''. | ||
| Line 119: | Line 118: | ||
|- | |- | ||
| − | || | + | || Type: |
| − | Type: | + | |
'''CREATE TABLE results (''' | '''CREATE TABLE results (''' | ||
| Line 149: | Line 147: | ||
|| Now let us insert a few sample records into the '''results''' table. | || Now let us insert a few sample records into the '''results''' table. | ||
| + | |||
Let us execute the query. | Let us execute the query. | ||
|- | |- | ||
| − | || | + | || Point to the output. |
|| The data is inserted successfully. | || The data is inserted successfully. | ||
| Line 176: | Line 175: | ||
|- | |- | ||
|| Highlight the output. | || Highlight the output. | ||
| + | |||
Highlight matching lines. | Highlight matching lines. | ||
|| Notice that we can see data from both the tables. | || Notice that we can see data from both the tables. | ||
| + | |||
Only the matching records from the tables are displayed. | Only the matching records from the tables are displayed. | ||
| Line 189: | Line 190: | ||
By default, the '''JOIN''' clause performs an '''INNER JOIN'''. | By default, the '''JOIN''' clause performs an '''INNER JOIN'''. | ||
| − | '''INNER JOIN''' | + | '''INNER JOIN''' explicitly returns only the matching records from both the tables. |
|- | |- | ||
| Line 227: | Line 228: | ||
Observe the output. | Observe the output. | ||
| − | |||
|- | |- | ||
|| Highlight output | || Highlight output | ||
| − | |||
| − | |||
|| You will notice that the result is the same as in the previous '''JOIN''' query. | || You will notice that the result is the same as in the previous '''JOIN''' query. | ||
Revision as of 11:09, 8 May 2026
Title of the Script: JOIN and INNER JOIN Clause
Author: Anjali Satdive / EduPyramids.
Keywords: PostgreSQL, pgAdmin4, Join clause, INNER JOIN clause, syntax, students, results, EduPyramids, video tutorial.
| Visual Cue | Narration |
|---|---|
| Title Slide | Welcome to this Spoken Tutorial on JOIN and INNER JOIN Clause. |
| Slide 2
Learning Objectives |
In this tutorial, we will learn about,
|
| Slide 3
System Requirements • Ubuntu 24.04 LTS • PostgreSQL version 18.1, and • PgAdmin4 version 9.11. |
To record this tutorial, I am using the following setup. |
|
Slide 4 Pre-requisites |
To follow this tutorial,
|
| Slide 5
Code Files The following code file is required to practice this tutorial. • jc-commands.txt This file is provided in the Code Files link on this tutorial page. Please download and extract the file. |
The following code file is required to practice this tutorial.
This file is provided in the Code Files link of this tutorial page. Please download and extract the file. |
| Let us get started. | |
| Slide 6
JOIN Clause |
The JOIN Clause combines rows from different tables using a related column. |
| Slide 7
Syntax of JOIN Clause SELECT column_name(s) FROM table1 JOIN table2 ON table1.common_column = table2.common_column; |
This is the syntax of the Joins clause.
SELECT column_names, specifies which columns to display. FROM table1 takes data from the first table. JOIN table 2 combines table 2 with table1. ON clause matches values in common columns of both the tables. |
| Highlight student table | So far, we have worked with a single table named students.
However, in real-world databases, data is usually stored in multiple related tables. To retrieve related data from multiple tables, we use the JOIN clause. |
| Showing Student table. | Let us create another table named results.
This table will store studentid and marks. |
| Type:
CREATE TABLE results ( studentid VARCHAR(10), marks INT ); Click the Execute query button. |
Let us type this query.
This creates a table named results. The studentid column will be common in both the tables. Let us execute the query to see the output. |
| Type:
INSERT INTO results VALUES ('S101', 85), ('S102', 90), ('S103', 78); Click the Execute query button. |
Now let us insert a few sample records into the results table.
Let us execute the query. |
| Point to the output. | The data is inserted successfully. |
| Type:
SELECT students.studentid, studentname, marks FROM students JOIN results ON students.studentid = results.studentid; Click the Execute query button. |
Now let us type this query.
This query combines the students and results tables using the studentid column. Let me execute the query. |
| Highlight the output.
Highlight matching lines. |
Notice that we can see data from both the tables.
Only the matching records from the tables are displayed. |
| Slide 10
INNER JOIN |
Let us learn about Inner Join.
By default, the JOIN clause performs an INNER JOIN. INNER JOIN explicitly returns only the matching records from both the tables. |
| Slide 11
Syntax of INNER JOIN SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.common_column = table2.common_column; |
Here is the syntax of the Inner Join. |
| Type:
SELECT students.studentid, studentname, marks FROM students INNER JOIN results ON students.studentid = results.studentid; Click the Execute query button.
|
Now let us type this query.
This query joins the students table and results table with matching columns. Click on the Execute Query button. Observe the output.
|
| Highlight output | You will notice that the result is the same as in the previous JOIN query.
|
| Highlight JOIN
Highlight INNER JOIN |
If we write JOIN, it automatically performs an INNER JOIN.
However, using INNER JOIN makes the query clearer and easier to read.
|
| Slide 10
Summary In this tutorial, we have learnt about, • JOIN Clause. • INNER JOIN Clause. • How to combine data from two related tables. |
With this, we come to the end of this tutorial.
Let us summarise. |
| Slide 11
Assignment As an Assignment, • Insert two new records into the table. • Execute the query using JOIN and INNER JOIN. • Observe the output. |
We encourage you to try this assignment.
|
| Slide 12
Thank you This Spoken Tutorial is brought to you by EduPyramids Educational Private Limited SINE IIT Bombay. |
Thank You. |