Modeling mutual friendship

# · ✸ 30 · 💬 2 · 5 days ago · minimalmodeling.substack.com · evilsimon
We can represent mutual friendship as a pair of directed friendships: Alice is a friend of Bob, Bob is a friend of Alice. CREATE TABLE mutual friendship );Establishing mutual friendship. CREATE TABLE mutual friendship, CONSTRAINT user1 user2 ids CHECK );.Getting the list of friends. SELECT user2 id FROM mutual friendship WHERE user1 id = 5 UNION ALL SELECT user1 id FROM mutual friendship WHERE user2 id = 5. SELECT 1 FROM mutual friendship WHERE user1 id = 3 AND user2 id = 5. If we don't want or cannot sort the IDs in our code, we have to consider both options in the SQL:.SELECT 1 FROM mutual friendship WHERE OR.Deleting friendship record. DELETE FROM mutual friendship WHERE user1 id = 3 AND user2 id = 5.
Modeling mutual friendship



Archive | Send Feedback | WebAssembly Version (beta)