
CREATE TABLE "Friend" (
	student_id INTEGER, 
	friend_id INTEGER, 
	PRIMARY KEY (student_id, friend_id), 
	FOREIGN KEY(student_id) REFERENCES "Highschooler" ("ID"), 
	FOREIGN KEY(friend_id) REFERENCES "Highschooler" ("ID")
)


CREATE TABLE "Highschooler" (
	"ID" INTEGER, 
	name TEXT, 
	grade INTEGER, 
	PRIMARY KEY ("ID")
)


CREATE TABLE "Likes" (
	student_id INTEGER, 
	liked_id INTEGER, 
	PRIMARY KEY (student_id, liked_id), 
	FOREIGN KEY(liked_id) REFERENCES "Highschooler" ("ID"), 
	FOREIGN KEY(student_id) REFERENCES "Highschooler" ("ID")
)

CREATE TABLE "Friend" (
	student_id INTEGER, 
	friend_id INTEGER, 
	PRIMARY KEY (student_id, friend_id), 
	FOREIGN KEY(student_id) REFERENCES "Highschooler" ("ID"), 
	FOREIGN KEY(friend_id) REFERENCES "Highschooler" ("ID")
)

/*
2 rows from Friend table:
student_id	friend_id
1510	1381
1510	1689
*/


CREATE TABLE "Highschooler" (
	"ID" INTEGER, 
	name TEXT, 
	grade INTEGER, 
	PRIMARY KEY ("ID")
)

/*
2 rows from Highschooler table:
ID	name	grade
1510	Jordan	9
1689	Gabriel	9
*/


CREATE TABLE "Likes" (
	student_id INTEGER, 
	liked_id INTEGER, 
	PRIMARY KEY (student_id, liked_id), 
	FOREIGN KEY(liked_id) REFERENCES "Highschooler" ("ID"), 
	FOREIGN KEY(student_id) REFERENCES "Highschooler" ("ID")
)

/*
2 rows from Likes table:
student_id	liked_id
1689	1709
1709	1689
*/
Show name of all students who have some friends and also are liked by someone else.
SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id INTERSECT SELECT T2.name FROM Likes AS T1 JOIN Highschooler AS T2 ON T1.liked_id  =  T2.id
[{'name': 'Alexis'}, {'name': 'Cassandra'}, {'name': 'Gabriel'}, {'name': 'Haley'}, {'name': 'Jessica'}, {'name': 'Jordan'}, {'name': 'Kris'}, {'name': 'Kyle'}]