Skip to content

Instantly share code, notes, and snippets.

@codesnik
Created September 15, 2015 14:28
Show Gist options
  • Save codesnik/3c7dc99893358d9350d5 to your computer and use it in GitHub Desktop.
Save codesnik/3c7dc99893358d9350d5 to your computer and use it in GitHub Desktop.
drop table if exists dogs, balls, dogs_balls;
create table dogs (
id int not null,
name varchar(255),
primary key (id)
);
create table balls (
id int not null,
color varchar(255),
primary key (id)
);
create table dogs_balls (
dog_id int not null,
ball_id int not null,
primary key (dog_id, ball_id)
);
insert into dogs (id, name) values
(1, 'Rex'),
(2, 'Belka'),
(3, 'Strelka'),
(4, 'Snoop'),
(5, 'Toto');
insert into balls (id, color) values
(1, 'red'),
(2, 'orange'),
(3, 'yellow'),
(4, 'green'),
(5, 'blue');
insert into dogs_balls (dog_id, ball_id) values
(1, 1), (1, 2), (1, 3),
(2, 1), (2, 2), (2, 3), (2, 4),
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
(4, 1), (4, 2), (4, 5),
(5, 5);
-- Find dogs which have red, orange, yellow and green balls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment