# Select

> Kalipso Studio 6.1 documentation · https://doc.sysdevmobile.com/kalipso/6.1/documentation/actions/group-database/select
>
> Selects records from a database table, like an SQL SELECT, with AVG, COUNT, MAX, MIN or SUM functions and a Where condition, into variables.

**Select**

Selects one or more records from the specified Database Table.

Action available for the following operating systems:

![OS Supported: Android, iOS, Win, Win32](https://doc.sysdevmobile.com/kalipso/assets/images/01_Supported_OS-5c02a51fd5080a410a07ee3ef72b6872.png)

## Parameters

SELECT

* **From** - Database Table where to retrieve the records from.
* **Function** - Function applied to the specified column. For further information about this parameter, please consult the documentation of your Database or SQLite if you're working off-line.
  * _AVG_ - Returns the average value of the specified **Column**.
  * _COUNT -_ Returns the number of records.
  * _MAX -_ Returns the maximum value of the specified **Column**.
  * _MIN_ - Returns the minimum value of the specified **Column**.
  * _SUM_ - Returns the sum of the values of the specified **Column**.
* **Column** - Column to be retrieved.
* **Into** _\<target> -_ Control or Variable where to store the retrieved value.
* **Nth From** - Table where to retrieve the records from.
* **Nth Function** _\<unquoted string> -_ Function applied to the specified column. For further information about this parameter, please consult the documentation of your Database or SQLite if you're working off-line.
* **Nth Column** _\<unquoted string> -_ Column to be retrieved.
* **Nth Into** _\<unquoted string> -_ Control or Variable where to store the retrieved value.
* **Ignore Database Masks** - If you've defined a **Mask** for the specified **Column** in the **Table** properties and:
  * This option is **checked** - The value is return the Kalipso format.
  * This option is **unchecked** - The value is returned with the **Mask** format.
* **Clear Data When No Record is Returned** - If this option is checked and no record is returned, all the targets (**Into** parameter) are cleared.
* **Where** _\<Kalipso Filter> or \<string> -_ Condition to specify which records should be retrieved. Check **Expressions** chapter for more information about **Kalipso Filter** and **String** expressions.

## Usage

This function generates a Select operation that exists in every SQL database, and is used to query the database and retrieve data according to one ore more conditions.

Consider the following Database Table, and the following Variables:

| **Products** |            |           |
| ------------ | ---------- | --------- |
| **Code**     | **Name**   | **Stock** |
| 1            | Coca Cola  | 100       |
| 2            | Pepsi Cola | 200       |
| 3            | Pork Chops | 300       |

| **Code** | **Name** | **Stock** |
| -------- | -------- | --------- |
| VAR(0)   | String   | Kalipso   |
| VAR(1)   | Numeric  | 0         |
| VAR(2)   | String   | Kalipso1  |

Consider that column **Code** is **Numeric**, column **Name** is **String** and column **Stock** is **Numeric**.\
Note that the table showing variables isn't a database table, its purpose is to show only the values and type of each variable.

### Example 1

| **From**       | **Function**             | **Column** | **Into** |
| -------------- | ------------------------ | ---------- | -------- |
| Products       | \<none>                  | Code       | VAR(0)   |
| Products       | \<none>                  | Name       | VAR(1)   |
| Products       | \<none>                  | Stock      | VAR(2)   |
|                |                          |            |          |
| **Where**      | FIELD(Products,Code)=001 |            |          |
| **Clear Data** | Yes                      |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | String   | 1         |
| VAR(1)       | Numeric  | Coca Cola |
| VAR(2)       | String   | 100       |

### Example 2

| **From**       | **Function**             | **Column** | **Into** |
| -------------- | ------------------------ | ---------- | -------- |
| Products       | AVG                      | Code       | VAR(0)   |
| Products       | \<none>                  | Name       | VAR(1)   |
| Products       | SUM                      | Stock      | VAR(2)   |
|                |                          |            |          |
| **Where**      | FIELD(Products,Code)=004 |            |          |
| **Clear Data** | Yes                      |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | Numeric  |           |
| VAR(1)       | String   |           |
| VAR(2)       | Numeric  |           |

### Example 3

| **From**       | **Function**             | **Column** | **Into** |
| -------------- | ------------------------ | ---------- | -------- |
| Products       | \<none>                  | Code       | VAR(0)   |
| Products       | \<none>                  | Name       | VAR(1)   |
| Products       | \<none>                  | Stock      | VAR(2)   |
|                |                          |            |          |
| **Where**      | FIELD(Products,Code)=004 |            |          |
| **Clear Data** | No                       |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | String   | kalipso   |
| VAR(1)       | Numeric  | 0         |
| VAR(2)       | String   | kalipso1  |

### Example 4

| **From**       | **Function**             | **Column** | **Into** |
| -------------- | ------------------------ | ---------- | -------- |
| Products       | AVG                      | Code       | VAR(0)   |
| Products       | \<none>                  | Name       | VAR(1)   |
| Products       | SUM                      | Stock      | VAR(2)   |
|                |                          |            |          |
| **Where**      | FIELD(Products,Code)=004 |            |          |
| **Clear Data** | No                       |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | Numeric  |           |
| VAR(1)       | String   |           |
| VAR(2)       | Numeric  |           |

:::info
In this example, the option _Clear Data_ is disabled but are used functions _AVG_ and _SUM_ , and because of that, this operation return on record, therefore types are enforced.
:::

### Example 5

| **From**       | **Function**            | **Column** | **Into** |
| -------------- | ----------------------- | ---------- | -------- |
| Products       | SUM                     | Stock      | VAR(2)   |
|                |                         |            |          |
| **Where**      | FIELD(Products,Code)<>0 |            |          |
| **Clear Data** | Yes                     |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | String   | kalipso   |
| VAR(1)       | Numeric  | 0         |
| VAR(2)       | Numeric  | 600       |

### Example 6

| **From**       | **Function**              | **Column** | **Into** |
| -------------- | ------------------------- | ---------- | -------- |
| Products       | MIN                       | Code       | VAR(0)   |
| Products       | COUNT                     | Name       | VAR(1)   |
| Products       | SUM                       | Stock      | VAR(2)   |
|                |                           |            |          |
| **Where**      | FIELD(Products,Code)<> "" |            |          |
| **Clear Data** | No                        |            |          |

_Result:_

| **Variable** | **Type** | **Value** |
| ------------ | -------- | --------- |
| VAR(0)       | Numeric  | 1         |
| VAR(1)       | String   | 3         |
| VAR(2)       | Numeric  | 600       |

:::warning
Notice that, as you can see in the examples above, Variable types are enforced, except if there is no result of the select operation and parameter **Clear Data** isn't checked.
:::

:::info
When you specify more than one condition in _Where_ parameter, the operator used between the conditions is "**AND**" or "**OR**".
:::

:::info
You can use the **RECORDCOUNT** Keyword to know how many records where returned.
:::
