> For the complete documentation index, see [llms.txt](https://help.novacuraflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.novacuraflow.com/development/flowscript/scripting-examples/sql-join-equivalent.md).

# SQL Join equivalent

How to use flow script to perform the equivalent of a SQL join between two table variables (not to be confused with the flow script join command, which does something else)

In the code below two dummy tables are created, usr and org.  The LeftJoin variable ("let LeftJoin"...) does the join between the tables with the FirstOrEmpty function. The result will be equal to a left join in SQL.  &#x20;

```fsharp
let usr = [name: "bob", id: 45, orgid: 1001]
& [name: "bill", id: 46, orgid: 1002]
& [name: "joe", id: 47, orgid: 1002]
& [name: "Anna", id: 47, orgid: 1004]; // this org does not exist 
 
let org = [orgname: "Ikea", id: 1001]
& [orgname: "Novacura", id: 1002]
& [orgname: "Flowington", id: 1003]; //This org has no users
  
let LeftJoin = select name, id, firstOrEmpty(org where id = orgid).orgname as orgname, orgid from usr;

let usersWithOrg = usr where any(org where id = orgid);
let usersWithoutOrg = usr where not any(org where id = orgid);


return LeftJoin;
```

The usersWithOrg  and usersWithoutOrg variables are similar to the "where in..." functionality in SQL, resulting in either the rows in the usr-table that does or does not have a corresponding row in the org table.&#x20;

By returning the different variables "LeftJoin", "usersWithOrg" or "usersWithoutOrg" in the last row in the code you can view the different results (but note as the left join yields another column from the joined table the numbers of columns in the output will be different)&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.novacuraflow.com/development/flowscript/scripting-examples/sql-join-equivalent.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
