Skip to content

Instantly share code, notes, and snippets.

@squadette
Created November 23, 2023 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squadette/7024e75262932e0b44171f5ad939529f to your computer and use it in GitHub Desktop.
Save squadette/7024e75262932e0b44171f5ad939529f to your computer and use it in GitHub Desktop.

http://sqlfiddle.com/#!9/b58cbd/1

This is a companion gist to the "Many explanations of JOIN are wrong, and people get confused" article.

Schema and initial data

CREATE TABLE t_a (
  id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
);
  
INSERT INTO t_a (id) VALUES (2), (3), (5);
  
CREATE TABLE t_b (
  id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
);
  
INSERT INTO t_b (id) VALUES (10), (20), (30), (40), (50);

Trivial match functions

SELECT t_a.id, t_b.id from t_a left join t_b on 1 = 1;

SELECT t_a.id, t_b.id from t_a left join t_b on 1 = 0;

etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment