CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Databases and SQL · 7 min · free

Working with Two Tables: Cartesian Product, Equi-join and Natural Join

7 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

A Cartesian product pairs every row with every row. An equi-join keeps only matching rows; a natural join matches same-named columns automatically. Rows multiply and columns add in a Cartesian product.

Follows the syllabus of: CBSE Class 10 Information Technology (402), CBSE Class 12 Computer Science (083), CBSE Class 12 Informatics Practices (065), CBSE Class 12 Information Technology (802)

On screen in this lesson

One big table repeats data

NameHNoHName
Riya1Green
Aman2Blue
Neha1Green
Kabir1Green

Why split data into tables

Less repetition: each house name is stored once
Fewer mistakes: no Green in one row and Greenn in another
Easy updates: rename a house in one place only
Less storage space wasted

Table STUDENT

RollNameHNo
1Riya1
2Aman2
3Neha1

Table HOUSE

HNoHName
1Green
2Blue

Key words first

Degree: number of columns in a table
Cardinality: number of rows in a table
Common column: same data in both tables, links them
Join: combine rows of two tables into one result

Every row with every row

NameS.HNoH.HNo
Riya11
Riya12
Aman21
Aman22
Neha11
Neha12

Quick answers

3 rows and 2 rows: how big is the Cartesian product?

6 rows and the columns added together.

How many times does a natural join show the common column?

Once.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. Riya's name is in one table and her house name is in another. How do we show them together in one result? Today we will learn why data is kept in separate tables. Then we will join them using the Cartesian product, the equi-join and the natural join.

Imagine a school keeps everything in one big table. Riya is in house number one, which is Green. Aman is in house two, which is Blue. Neha is also in house one, so Green is typed again. Kabir is in house one too, so Green is typed a third time.

This repetition causes problems, so we split the data into two tables. First, each house name is stored only once. Second, there are fewer typing mistakes, because nobody types Green again and again. Third, if a house is renamed, we change it in one row only. Fourth, the database uses less storage space.

Here is our first table, called student. It has a roll number, a name and a house number. Riya has roll number one and is in house one. Aman has roll number two and is in house two. Neha has roll number three and is in house one.

The second table is called house. House number one is Green. House number two is Blue. The column H No is present in both tables, so it is called the common column.

Before we join, learn four words. Degree means the number of columns, so student has a degree of three. Cardinality means the number of rows, so student has a cardinality of three. A common column holds the same kind of data in both tables and links them. A join combines rows from two tables into one result.

The simplest way to use two tables is to list both after from, separated by a comma. There is no condition at all. This gives the Cartesian product, also called a cross join. Every row of the first table is paired with every row of the second table.

Here is part of that result, showing the name and both house number columns. Riya is paired with house one. Riya is also paired with house two, which is wrong for her. Aman is paired with house one, also wrong. Aman is paired with house two, which is correct. Neha is paired with house one, which is correct. And Neha is paired with house two, which is wrong.

Exams often ask you to calculate the size of this result. The number of rows is the rows of the first table multiplied by the rows of the second. The number of columns is the columns of the first table plus the columns of the second. So here we get three times two, six rows, and three plus two, five columns. With a thousand students and forty clubs, you get forty thousand rows, and most of them are meaningless.

To keep only the correct pairs, we add a condition. The where clause says student dot H No equals house dot H No. Only rows where the two house numbers are equal are kept. A join that matches columns using the equals sign is called an equi-join. Now Riya is Green, Aman is Blue and Neha is Green.

Remember four rules for the equi-join. The condition uses the equals sign on the common column. When both tables have a column with the same name, write the table name, a dot, then the column name. If you write select star, the common column appears two times in the output. Many books also write it as join, with the condition after the word on.

Typing full table names again and again is slow. So we give each table a short name, called an alias. Here S stands for student and H stands for house. We can also add more conditions with and. Pause and predict. Which students print if we ask for house Green? Riya and Neha, because both are in house one.

A natural join does the equi-join for us. We write natural join between the two table names, with no condition. SQL finds the column with the same name in both tables and matches on it. In MySQL, the common column H No comes first, and it appears only once. So the result has four columns, not five.

Let us compare the three ways side by side. A Cartesian product has no condition, and it shows every pair. In an equi-join, you write the equals condition, and select star shows the common column twice. In a natural join, SQL matches the same-named column automatically and shows it only once.

The natural join has some traps. The common columns must have exactly the same name in both tables. If two pairs of columns share names, it matches on both of them. And if no column name matches, it quietly gives you the full Cartesian product.

Let us revise what we learned today. We split data into tables to avoid repetition and mistakes. A Cartesian product pairs every row with every row, so rows multiply and columns add. An equi-join uses a where condition with equals on the common column. A natural join matches same-named columns by itself and shows the common column once. Try these queries on two small tables of your own.

Courses that teach this

CourseUnit
CBSE Class 10 Information Technology (402)Database Management System using LibreOffice Base
CBSE Class 12 Computer Science (083)Database Management
CBSE Class 12 Informatics Practices (065)Database Query using SQL
CBSE Class 12 Information Technology (802)Database Concepts - RDBMS Tool

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →