{"id":3441,"date":"2016-03-16T12:42:00","date_gmt":"2016-03-16T12:42:00","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3441"},"modified":"2016-03-16T12:42:00","modified_gmt":"2016-03-16T12:42:00","slug":"rethinkdb-left-join-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/rethinkdb-left-join-example\/","title":{"rendered":"RethinkDB: LEFT JOIN Example"},"content":{"rendered":"<p>In RethinkDB, a LEFT JOIN looks exactly like INNER JOIN:<\/p>\n<pre lang=\"javascript\">\nr.db('test')\n .table('user_actions')\n .outerJoin(r.table('users'),\n    (action, user) => \n      action('user_id').eq(user('id')))\n .zip()\n<\/pre>\n<p>A couple notes here: to achieve an expected result you need to add &#8220;.zip&#8221; at the end, otherwise you get a data structure with &#8220;left&#8221; and &#8220;right&#8221;. <\/p>\n<p>It&#8217;s also important to note that despite the name this is actually a left join. If you want to do a right join, you need to swap the arguments to the function. If you want full outer join, you&#8217;ll need to do left and right joins, then union the results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In RethinkDB, a LEFT JOIN looks exactly like INNER JOIN: r.db(&#8216;test&#8217;) .table(&#8216;user_actions&#8217;) .outerJoin(r.table(&#8216;users&#8217;), (action, user) => action(&#8216;user_id&#8217;).eq(user(&#8216;id&#8217;))) .zip() A couple notes here: to achieve an expected result you need to add &#8220;.zip&#8221; at the end, otherwise you get a data structure with &#8220;left&#8221; and &#8220;right&#8221;. It&#8217;s also important to note that despite the name this &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/rethinkdb-left-join-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RethinkDB: LEFT JOIN Example&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[160,462,466,523],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3441"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3441"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3441\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}