· 7 years ago · Sep 30, 2018, 10:40 PM
1sqlite> CREATE TABLE IF NOT EXISTS Users (Name TEXT UNIQUE);
2sqlite> CREATE TABLE IF NOT EXISTS 'Coffee Breaks' (Person1 TEXT, Person2 TEXT);
3sqlite> insert into users (Name) VALUES ('Casey'), ('Jake'), ('Mark'), ('Steve');
4sqlite> insert into "Coffee Breaks" (Person1, Person2) VALUES ('Steve', 'Casey');
5sqlite>
6sqlite> WITH bilateral(p1, p2) AS (SELECT Person1 AS p1, Person2 AS p2 FROM "Coffee Breaks"
7 ...> UNION ALL SELECT Person2 AS p1, Person1 AS p2 FROM "Coffee Breaks"
8 ...> GROUP BY p1, p2)
9 ...> SELECT u1.Name || ' has not had coffee with ' || u2.Name FROM Users u1, Users u2
10 ...> LEFT JOIN bilateral bi ON u1.Name=bi.p1 AND u2.Name=bi.p2
11 ...> WHERE bi.p1 IS NULL AND u1.Name != u2.Name;
12Casey has not had coffee with Jake
13Casey has not had coffee with Mark
14Jake has not had coffee with Casey
15Jake has not had coffee with Mark
16Jake has not had coffee with Steve
17Mark has not had coffee with Casey
18Mark has not had coffee with Jake
19Mark has not had coffee with Steve
20Steve has not had coffee with Jake
21Steve has not had coffee with Mark
22sqlite>