Last active
January 11, 2024 16:58
-
-
Save Mevrael/bc645cb63a2d3bbae3fb43366b47f313 to your computer and use it in GitHub Desktop.
Revisions
-
Mevrael revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Example for MySQL 5.7 how to use JOIN on 2 tables without junction table using new JSON column type. # Let say we have 2 tables: posts and users # Users may like posts # We store the IDs of users who liked each post in posts.liked column which is a JSON array -
Mevrael revised this gist
Nov 10, 2016 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,8 @@ # Example for MySQL 5.7 how to use JOIN two tables without junction table using new JSON column type. # Let say we have 2 tables: posts and users # Users may like posts # We store the IDs of users who liked each post in posts.liked column which is a JSON array # which might have a content like "[1, 2, 5, 10]" SELECT posts.id AS post_id, users.id AS liked_by_user_id FROM posts JOIN users ON JSON_CONTAINS(posts.liked, CAST(users.id AS CHAR)) -
Mevrael revised this gist
Nov 10, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,2 @@ SELECT u1.id AS id1, u2.id AS id2 FROM users AS u1 JOIN users AS u2 ON JSON_CONTAINS(u1.friends, CAST(u2.id AS CHAR)) -
Mevrael created this gist
Nov 10, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ ```mysql SELECT u1.id AS id1, u2.id AS id2 FROM users AS u1 JOIN users AS u2 ON JSON_CONTAINS(u1.friends, CAST(u2.id AS CHAR)) ```