1"use strict";(globalThis.webpackChunkkysely_site=globalThis.webpackChunkkysely_site||[]).push([[4935],{5334(e,n,i){i.r(n),i.d(n,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>l,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"examples/join/subquery-join","title":"Subquery join","description":"You can join a subquery by providing two callbacks:","source":"@site/docs/examples/join/0040-subquery-join.mdx","sourceDirName":"examples/join","slug":"/examples/join/subquery-join","permalink":"/docs/examples/join/subquery-join","draft":false,"unlisted":false,"editUrl":"https://github.com/kysely-org/kysely/tree/master/site/docs/examples/join/0040-subquery-join.mdx","tags":[],"version":"current","sidebarPosition":40,"frontMatter":{"title":"Subquery join"},"sidebar":"tutorialSidebar","previous":{"title":"Complex join","permalink":"/docs/examples/join/complex-join"},"next":{"title":"INSERT","permalink":"/docs/category/insert"}}');var o=i(1058),t=i(4801),r=i(2360);const l={title:"Subquery join"},a="Subquery join",c={},d=[];function u(e){const n={a:"a",admonition:"admonition",h1:"h1",header:"header",li:"li",p:"p",ul:"ul",...(0,t.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.header,{children:(0,o.jsx)(n.h1,{id:"subquery-join",children:"Subquery join"})}),"\n",(0,o.jsx)(n.p,{children:"You can join a subquery by providing two callbacks:"}),"\n","\n","\n",(0,o.jsx)("div",{style:{marginBottom:"1em"},children:(0,o.jsx)(r.Q,{code:"const result = await db.selectFrom('person')\n .innerJoin(\n (eb) => eb\n .selectFrom('pet')\n .select(['owner_id as owner', 'name'])\n .where('name', '=', 'Doggo')\n .as('doggos'),\n (join) => join\n .onRef('doggos.owner', '=', 'person.id'),\n )\n .selectAll('doggos')\n .execute()"})}),"\n",(0,o.jsxs)(n.admonition,{title:"More examples",type:"info",children:[(0,o.jsxs)(n.p,{children:["The API documentation is packed with examples. The API docs are hosted ",(0,o.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/",children:"here"}),",\nbut you can access the same documentation by hovering over functions/methods/classes in your IDE. The examples are always\njust one hover away!"]}),(0,o.jsx)(n.p,{children:"For example, check out these sections:"}),(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#innerJoin",children:"innerJoin method"})}),"\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#leftJoin",children:"leftJoin method"})}),"\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#rightJoin",children:"rightJoin method"})}),"\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#fullJoin",children:"fullJoin method"})}),"\n"]})]})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(u,{...e})}):u(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.