Created
May 17, 2019 20:12
-
-
Save beardedtim/d366a6326e0ba211e4f08d8200faddee to your computer and use it in GitHub Desktop.
Left Joins for days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* create some nodes to connect */ | |
| INSERT INTO nodes(title) VALUES | |
| ('Linux'), | |
| ('Operating System'); | |
| /* create a connection to connect nodes with */ | |
| INSERT INTO links(title) VALUES ('is_a'); | |
| /* And connect the two nodes created via the link */ | |
| INSERT INTO connections(node_a, link, node_b) VALUES | |
| (1, 1, 2); | |
| SELECT | |
| node_a.title AS node_a, | |
| node_b.title AS node_b, | |
| link.title AS link, | |
| connection.id AS id | |
| FROM connections connection | |
| LEFT JOIN nodes node_a | |
| ON node_a.id = connection.node_a | |
| LEFT JOIN nodes node_b | |
| ON node_b.id = connection.node_b | |
| LEFT JOIN links link | |
| ON link.id = connection.link; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment