Skip to content

Instantly share code, notes, and snippets.

@DGaffney
Created May 16, 2011 02:18
Show Gist options
  • Select an option

  • Save DGaffney/973809 to your computer and use it in GitHub Desktop.

Select an option

Save DGaffney/973809 to your computer and use it in GitHub Desktop.
#Table Friendships
+----+------------+-------------------+------------------+------------+------------+
| id | dataset_id | following_user_id | followed_user_id | created_at | deleted_at |
+----+------------+-------------------+------------------+------------+------------+
| 1 | 1 | 12 | 13348 | NULL | NULL |
| 2 | 1 | 107 | 13348 | NULL | NULL |
| 3 | 1 | 274 | 13348 | NULL | NULL |
| 4 | 1 | 324 | 13348 | NULL | NULL |
| 5 | 1 | 418 | 13348 | NULL | NULL |
| 6 | 1 | 422 | 13348 | NULL | NULL |
| 7 | 1 | 455 | 13348 | NULL | NULL |
| 8 | 1 | 456 | 13348 | NULL | NULL |
| 9 | 1 | 509 | 13348 | NULL | NULL |
| 10 | 1 | 544 | 13348 | NULL | NULL |
| 11 | 1 | 12 | 13349 | NULL | NULL |
| 12 | 1 | 107 | 13349 | NULL | NULL |
| 13 | 1 | 274 | 13349 | NULL | NULL |
| 14 | 1 | 324 | 13349 | NULL | NULL |
| 15 | 1 | 418 | 13349 | NULL | NULL |
| 16 | 1 | 422 | 13349 | NULL | NULL |
| 17 | 1 | 455 | 13350 | NULL | NULL |
| 18 | 1 | 456 | 13350 | NULL | NULL |
| 19 | 1 | 509 | 13350 | NULL | NULL |
| 20 | 1 | 544 | 13350 | NULL | NULL |
+----+------------+-------------------+------------------+------------+------------+
#With data in a structure like this, how would I be able to find out the intersections of following_user_id from followed_user_id? In other words, followed_user_id of
#13348 and 13349 have 6 similar start_id rows (following_user_ids of 12,107,274,324,418,422), 13348 and 13350 have 4 (455,456,509,544), and 13349
#and 13350 have zero similar rows.
#Query I have been trying: select count(a.following_user_id) from friendships as a, friendships as b, friendships as c where a.following_user_id=b.following_user_id=c.following_user_id and (a.followed_user_id=13348 and b.followed_user_id=13349 and c.followed_user_id=13350);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment