Created
March 27, 2015 16:46
-
-
Save saxbophone/f13405519dc69d527362 to your computer and use it in GitHub Desktop.
This file contains 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 table authors( | |
id integer primary key, | |
first_name varchar(127), | |
last_name varchar(127) | |
); | |
create table books( | |
id integer primary key, | |
title varchar(255), | |
author integer, | |
foreign key(author) references authors(id) | |
); | |
insert into authors(first_name, last_name) values('Mary', 'Shelley'); | |
insert into authors(first_name, last_name) values('Jane', 'Austen'); | |
insert into books(title, author) values('Frankenstein', 1); | |
insert into books(title, author) values('Jane Eyre', 2); | |
insert into books(title, author) values('Wuthering Heights', 2); | |
select books.id, books.title, authors.first_name, authors.last_name from books join authors where books.author == authors.id; | |
-- id title first_name last_name | |
-- 1 Frankenstein Mary Shelley | |
-- 2 Jane Eyre Jane Austen | |
-- 3 Wuthering Heights Jane Austen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment