
CREATE TABLE "Person" (
	name VARCHAR(20), 
	age INTEGER, 
	city TEXT, 
	gender TEXT, 
	job TEXT, 
	PRIMARY KEY (name)
)


CREATE TABLE "PersonFriend" (
	name VARCHAR(20), 
	friend VARCHAR(20), 
	year INTEGER, 
	FOREIGN KEY(name) REFERENCES "Person" (name), 
	FOREIGN KEY(friend) REFERENCES "Person" (name)
)

CREATE TABLE "Person" (
	name VARCHAR(20), 
	age INTEGER, 
	city TEXT, 
	gender TEXT, 
	job TEXT, 
	PRIMARY KEY (name)
)

/*
2 rows from Person table:
name	age	city	gender	job
Alice	25	new york city	female	student
Bob	35	salt lake city	male	engineer
*/


CREATE TABLE "PersonFriend" (
	name VARCHAR(20), 
	friend VARCHAR(20), 
	year INTEGER, 
	FOREIGN KEY(name) REFERENCES "Person" (name), 
	FOREIGN KEY(friend) REFERENCES "Person" (name)
)

/*
2 rows from PersonFriend table:
name	friend	year
Alice	Bob	10
Zach	Dan	12
*/
Find Alice's friends of friends.
SELECT DISTINCT T4.name FROM PersonFriend AS T1 JOIN Person AS T2 ON T1.name  =  T2.name JOIN PersonFriend AS T3 ON T1.friend  =  T3.name JOIN PersonFriend AS T4 ON T3.friend  =  T4.name WHERE T2.name  =  'Alice' AND T4.name != 'Alice'
[{'name': 'Zach'}]