> For the complete documentation index, see [llms.txt](https://outerbase.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://outerbase.gitbook.io/untitled/query-builder/select.md).

# Select

Fetching data from your SQL database happens with a `SELECT` statement.

Typically in SQL the syntax would look like the below statement which would return all of the rows from the table, `table_name` and for each row only return the columns named `column_1` and `column_2` – but nothing else.

```sql
SELECT column_1, column_2 FROM table_name
```

When using the Outerbase query builder you can accomplish the same SQL statement with the following code.

<pre class="language-typescript"><code class="lang-typescript"><strong>const { data, error } = db
</strong><strong>    .selectFrom([
</strong><strong>        { table: 'table_name', columns: ['column_1', 'column_2'] }
</strong><strong>    ])
</strong><strong>    .query()
</strong></code></pre>

## Specifying a schema

For some databases, tables are nested within a schema which you can in some ways think of as a folder to help categorize your tables intent. By default many database engines have a root schema named `public` but you do not need to specify `public` in your SQL statements as it is implied.

However, if you have custom schemas then it is important to specify a schema before the table. In SQL it might look like the statement below.

```sql
SELECT * FROM my_schema.table_name
```

Because the table lives as a child of `my_schema` we must specify the parent child relationship in the query so the database engine knows where to find that table specifically.

To accomplish this in the query builder you can do so by specifying the schema in addition to the table name and columns.

```typescript
const { data, error } = db
    .selectFrom([
        { 
            schema: 'my_schema',
            table: 'table_name',
            columns: ['*']
    ])
    .query()
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://outerbase.gitbook.io/untitled/query-builder/select.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
