🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to PostgreSQL Notes
Topic #31

PostgreSQL INNER JOIN


INNER JOIN

The INNER JOIN keyword selects records that have matching values in both tables.

Let's look at an example using our dummy testproducts table:

 testproduct_id |      product_name
| category_id
----------------+------------------------+-------------

1 | Johns Fruit Cake       |
3

2 | Marys Healthy Mix      |
9

3 | Peters Scary Stuff     |
10

4 | Jims Secret Recipe     |
11

5 | Elisabeths Best Apples |
12

6 | Janes Favorite Cheese  |
4

7 | Billys Home Made Pizza |
13

8 | Ellas Special Salmon   |
8

9 | Roberts Rich Spaghetti |
5
            10 |
Mias Popular Ice        |
14
(10 rows)

We will try to join the testproducts table with the categories table:

 category_id | category_name  |
description
-------------+----------------+------------------------------------------------------------

1 | Beverages      | Soft drinks, coffees, teas,
beers, and ales

2 | Condiments     | Sweet and savory sauces, relishes,
spreads, and seasonings

3 | Confections    | Desserts, candies, and sweet breads

4 | Dairy Products | Cheeses

5 | Grains/Cereals | Breads, crackers, pasta, and cereal

6 | Meat/Poultry   | Prepared meats

7 | Produce        | Dried fruit and bean
curd
           8 |
Seafood        | Seaweed and fish
(8
rows)

Notice that many of the products in testproducts have a category_id that does not match any of the categories in the categories table.

By using INNER JOIN we will not get the records where there is not a match, we will only get the records that matches both tables:

Example

SELECT
testproduct_id, product_name, category_name
FROM testproducts
INNER JOIN categories ON
testproducts.category_id = categories.category_id;

Result

 testproduct_id |      product_name
| category_name
----------------+------------------------+----------------

1 | Johns Fruit Cake       | Confections

6 | Janes Favorite Cheese  | Dairy Products

8 | Ellas Special Salmon   | Seafood

9 | Roberts Rich Spaghetti | Grains/Cereals
(4 rows)

Note: JOIN and INNER JOIN will give the same result. INNER is the default join type for JOIN, so when you write JOIN the parser actually writes INNER JOIN.

Want to go beyond the notes?

Join CodingNow 2.0's PostgreSQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

PostgreSQL INNER JOIN – FAQs

Quick answers about learning PostgreSQL INNER JOIN in PostgreSQL.

This free note from CodingNow 2.0 explains PostgreSQL INNER JOIN in PostgreSQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every PostgreSQL topic on CodingNow 2.0, including PostgreSQL INNER JOIN, is 100% free with no signup required.
With focused practice, most students grasp PostgreSQL INNER JOIN in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now