Query from many-to-many relationship
<p>Student stores a list of student name and Friend stores relationship between students.</p>

<pre><code>Create table Student (
id int NOT NULL AUTO_INCREMENT,
name varchar(35),
PRIMARY KEY (id)
);

insert into Student (name) values ('John');
insert into Student (name) values ('Kelly');
insert into Student (name) values ('Mary');

Create table Friend (
  id_from int NOT NULL REFERENCES Student(id),
  id_to int NOT NULL REFERENCES Student(id),
  PRIMARY KEY (id_from, id_to)
);

insert into Friend (id_from,id_to) values (1, 3);
insert into Friend (id_from,id_to) values (1, 2);
insert into Friend (id_from,id_to) values (3, 2);
</code></pre>

<p>How can I query all friends of "John", for example, in MySql? The schema is here.</p>

<p><a href="http://sqlfiddle.com/#!9/aeacd/1" rel="nofollow">http://sqlfiddle.com/#!9/aeacd/1</a></p>