SQL Corgs Explain Inner Joins

SQL Corgs Explain Inner Joins

Kendra Little | April 15, 2024

Joins are essential. The SQL Corgs introduce you to INNER joins in this animated short. When you need to combine data from multiple tables, INNER joins are your go-to tool: they only return rows where there’s a match in both tables.

Watch as Freyja and Stormy demonstrate how matching on color brings their favorite toys together, with sample code you can run yourself.

Sample code

Freyja and Stormy love sample code, although their typing isn’t the best. This works in SQL Server:

CREATE TABLE
    #stormy
(
    name sysname,
    color sysname
);

INSERT
    #stormy
VALUES
    ('rope', 'blue'),
    ('bone', 'blue'),
    ('lobster', 'red'),
    ('ball', 'orange');

CREATE TABLE
    #freyja
(
    name sysname,
    color sysname
);

INSERT
    #freyja
VALUES
    ('bone', 'orange'),
    ('rope', 'orange'),
    ('ball', 'blue'),
    ('duck', 'green');

SELECT
    s.color,
    s.name,
    f.color,
    f.name
FROM #stormy AS s
JOIN #freyja AS f
  ON s.color = f.color;