Skip to content

Instantly share code, notes, and snippets.

@fodra
Created February 7, 2018 11:26
Show Gist options
  • Save fodra/a631a1f086551d47d744a0beaf508589 to your computer and use it in GitHub Desktop.
Save fodra/a631a1f086551d47d744a0beaf508589 to your computer and use it in GitHub Desktop.
All about joins in PostgreSQL.

Joins

Retrieve the start times of members' bookings

The main thing here is the bit where you rename the table to something shorter: cd.members > mem. However this site clearly doesn't do that.

The concept is simple enough, you just have to join two tables that are related via a foreign key. When you join them together, you get a more detailed row.

select bks.starttime from cd.members mem inner join cd.bookings bks on mem.memid = bks.memid where mem.firstname = 'David' and mem.surname = 'Farrell';

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