> For the complete documentation index, see [llms.txt](https://docs.launchboard.app/cxd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.launchboard.app/cxd/code-web-app-data-visualization/dashboard-template-tutorial/2-sql-introduction.md).

# 2 - SQL Introduction

[Structured Query Language (SQL)](https://www.w3schools.com/sql/sql_intro.asp) is a standard language for accessing and manipulating databases. Databases are just a group of data tables. Below is an example of a table called "Degrees" that could be in a database.

| Major                 | StartingMedianSalary | MidCareerMedianSalary |
| --------------------- | -------------------- | --------------------- |
| Accounting            | 46000.00             | 77100.00              |
| Aerospace Engineering | 57700.00             | 101000.00             |
| Agriculture           | 42600.00             | 71900.00              |
| Anthropology          | 36800.00             | 61500.00              |

We can then use SQL to "filter" the table. For example the following SQL statement..

```sql
SELECT Major, StartingMedianSalary FROM Degrees
```

would generate the following table.

| Major                 | StartingMedianSalary |
| --------------------- | -------------------- |
| Accounting            | 46000.00             |
| Aerospace Engineering | 57700.00             |
| Agriculture           | 42600.00             |
| Anthropology          | 36800.00             |

We simply `SELECT` columns `FROM` a table. Above we selected the columns "Major" and "StartingMedianSalary" from the "Degrees" table.&#x20;

We can also use `*` (a wild card) for the columns to get all the columns. So, `SELECT * FROM Degrees` will result in the full table.&#x20;

### Try It OUT

**1 - Find the following Javascript in your&#x20;*****code.js*****&#x20;file.**

```
viz.chart({
    sql:"SELECT * FROM Degrees",
    chartType:"Table",
    containerId:"chart2"
});
```

Notice how this code generates the table in your web view, where the table has a lot of columns (actually, all of them).&#x20;

**2 - Now change the SQL to the following to select only two columns.**

`SELECT Major, StartingMedianSalary FROM Degrees`

Run your web app and notice how the table has changed.

**3 - Now try the following SQL to get all the columns from a different table.**

&#x20;`SELECT * FROM States`

This gets a different table, "States", that can be found in our example database.

**4 - Go to** [**this Google Sheet**](https://docs.google.com/spreadsheets/d/1o60fGIa1USsQTXyYc-Qh-eYQ2TlHaaEC_iSdzJ7WbD4/edit?usp=sharing) **to see the example database and notice how each sheet (tab) is a table with a unique name.**

You will use SQL to get the right data from a database (Google Sheets file) for the charts you want to display. Next, let's look at producing the actual charts.&#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://docs.launchboard.app/cxd/code-web-app-data-visualization/dashboard-template-tutorial/2-sql-introduction.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.
