Say you have two tables. One is a regular table which maps ID's to NAME's and the other is a table of three ID's. Table: Highschooler
Table:TheThree
Say you want to generate a new table based upon these two such that it looks like this: Table: TheResult
This is how it is formed. select Y1.name, Y2.name, Y3.name, from TheThree as X inner join Highschooler as Y1 on Y1.id=X.ID1 inner join Highschooler as Y2 on Y2.ID=X.id2 inner join Highschooler as Y3 on Y3.ID=X.ID3 Now, if the table TheThree is actually the result of a query you can do this: sqlite3 social.db "select Y1.name, Y1.grade, Y2.name, Y2.grade, Y3.name, Y3.grade from (select A.ID1 ID1, A.ID2 ID2, B.ID2 ID3 from Likes A join Friend B on A.ID1 <> B.ID2 and A.ID2 = B.ID1 where (A.ID1 not in (select ID1 from Friend where A.ID1=ID1 and A.ID2=ID2) and B.ID2 in (select ID1 from Friend where A.ID1=ID2))) as X inner join Highschooler as Y1 on Y1.id=X.ID1 inner join Highschooler as Y2 on Y2.ID=X.id2 inner join Highschooler as Y3 on Y3.ID=X.ID3" |