Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Created May 17, 2019 20:12
Show Gist options
  • Select an option

  • Save beardedtim/d366a6326e0ba211e4f08d8200faddee to your computer and use it in GitHub Desktop.

Select an option

Save beardedtim/d366a6326e0ba211e4f08d8200faddee to your computer and use it in GitHub Desktop.
Left Joins for days
/* 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