SQL-101-Basics
  • Introduction
  • Part 1: Transact-SQL
    • 1.0: Getting Started with T-SQL
    • 1.1: Create Database
    • 1.2: Drop Database
    • 1.3: Create Table
    • 1.4: Insert
    • 1.5: Update
    • 1.6: Read
    • 1.7: Alter
    • 1.8: Customer Table
    • 1.9: Diagramming Notation
    • 1.10: Foreign Keys
    • 1.11: Join
    • 1.12: Solutions
  • Part 2: PostgreSQL
    • 2.0: Getting Started with PostgreSQL
    • 2.1: Create Database
    • 2.2: Drop Database
    • 2.3: Create Table
    • 2.4: Insert
    • 2.5: Update
    • 2.6: Read
    • 2.7: Alter
    • 2.8: Customer Table
    • 2.9: Diagramming Notation
    • 2.10: Foreign Keys
    • 2.11: Join
    • 2.12: Solutions
  • Part 3: T-SQL Challenges
    • 3.0: Introduction
    • 3.1: Challenge 1
    • 3.2: Challenge 2
    • 3.3: Challenge 3
    • 3.4: Challenge 4
    • 3.5: Solutions
  • Part 4: PostgreSQL Challenges
    • 4.0: Introduction
    • 4.1: Challenge 1
    • 4.2: Challenge 2
    • 4.3: Challenge 3
    • 4.4: Challenge 4
    • 4.5: Solutions
  • Part 5: Resources
    • 5.0: Resources
Powered by GitBook
On this page
  1. Part 2: PostgreSQL

2.11: Join

Previous2.10: Foreign KeysNext2.12: Solutions

Last updated 7 years ago

In this lesson, you'll learn how to query data from multiple tables. This short will introduce the concept of an "inner join," which is the type of join you'll be using below. You can also read more about joining tables in PostgreSQL by clicking .

Start by copying and pasting this code into a query in pgAdmin. This will populate the table you created in the previous lesson.

INSERT INTO Purchases (
    VALUES (1, 1, 1, 5),
    (2, 1, 2, 5),
    (3, 2, 4, 3)
);

This is what the resulting table should look like:

Now, write a query that will return a table containing the customer's first names that have a PurchaseID. You'll have to use an "INNER JOIN" to accomplish this. Remember that you are also working with multiple tables, so consider which tables have the data you are querying for. Finally, think about what columns these tables have in common.

The resulting table output from your query should look like this:

To see the solution for this challenge, click on . For additional challenges, please continue to .

video
here
Part Four
2.12 Solutions
Purchase table after insert
Table output inner join