> For the complete documentation index, see [llms.txt](https://community-test.logicnets.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://community-test.logicnets.com/release-9/platform-documentation/process-node-parts/get-records.md).

# Get Records

## Description

The part offers an easy way to access data from the data table in the database and pull it into a session for use by your application.

## Use

You can use this part to pull data stored in a data table into your session.

## Editor Fields

| Field Name            | Description/Use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Type/Options | Optional/Mandatory |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------ |
| Data-object           | This is the collection name in the context into which the system will store the returned data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Text         | Mandatory          |
| Collection            | Check this box if the returned data contains multiple rows. If not checked, the system will only return the first record.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Checkbox     | Optional           |
| Distinct              | If this checkbox is checked the part eliminates duplicates from the returned data and returns a distinct value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Checkbox     | Optional           |
| Data source(s)        | This is the name of the collection of data source(s) name in the database. It corresponds to the FROM clause in SQL query. For example, select \* from tb1, tb2, tb3; It select records from three tables.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Collection   | Mandatory          |
| Selection             | <p>This is the filter query of the data, and it corresponds to the WHERE clause in the SQL query. For example, select \* from temperature where temperature.value>5; It returns all records of which the value is larger than 5.<br>Selection operators vary by variable type as follows:<br>- <strong>numeric fields</strong>: equals, not equals, is larger (or equal) than, is smaller (or equal) than, in, not in<br>- <strong>text fields</strong>: equals, not equals, is not, like, equals or empty, in, not in<br>Use <strong>like</strong> with leading and/or trailing wildcard (%) if necessary.<br><strong>In</strong> and <strong>not in</strong> comparison value must be a collection as text, quoted, and comma separated.<br>- Use the <strong>format variable</strong> part to do the conversion so that apostrophes are escaped correctly for the SELECT statement.<br>- Note that if the collection is empty, this term only is dropped from the query to avoid an error from "<em>where target in {null}</em>."<br>You can build complex selection criteria using the editor by using <strong>AND/OR</strong> (toggle to switch) and adding parentheses around specific terms to define the precise selection rules.<br><em>Advanced Note</em>: While less commonly used, you can also apply greater than/sm, as per SQL.</p> | Collection   | Optional           |
| Columns               | <p>These are the selected columns of the data table(s). It corresponds to the SELECT clause in SQL query. For example, select date, value from temperature;. Here id date and value is the 'column' name. 'Data object' name is the data path name you want the data to be stored into in the context.<br>In addition the following aggregate functions are supported: MIN, MAX, COUNT, AVG, SUM and GROUP\_CONCAT.<br>When a 'group\_by' is specified, the aggregate functions: MIN, MAX can be used for selecting the record with the column with the lowest or highest value in the set of grouped records. The COUNT function can be used for counting the total numbers of records per group. The AVG and SUM function can be used for calculating the average or the sum of the values in a column of the records per group. The GROUP\_CONCAT can be used for concatenating all the values of a column of the records per group. For the latter, you can alter the default separator ',', by setting the <em>record\_format.separator</em> for the column.</p>                                                                                                                                                                                                                                                                              | Collection   | Mandatory          |
| Group by              | This allows you to group the returned data by the given column, and this value corresponds to the GROUP BY clause in SQL query. For example, select \* from temperature group by day; It returns all data which is grouped by the day value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Collection   | Optional           |
| Having                | This field allows you to add additional conditions. It corresponds to the HAVING clause in SQL query. For example, select \* from temperature group by temperature.day having temperature.value>5; It returns all the data when value is larger than 5. Please be noted that a GROUP BY clause is required before the HAVING clause.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Collection   | Optional           |
| Order by              | This field allows you to sort the returned data by the given column. It corresponds to the ORDER BY clause in SQL query .For example, select \* from temperature order by date desc; It returns all data which is sorted by the date in the descending order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Collection   | Optional           |
| Log data object       | <p>This is the name of the data object that stores the error messages from the execution of the database parts: add data record, get data record, update data record, delete data record, and import values. When the log data object is specified, the error message and stack trace of a database part will be stored to the object in case of errors.<br>When used by multiple database parts, the Log data object will store the cumulative list of error messages from the different parts.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Text         | Optional           |
| Reset log data object | When this field is checked the system will clear the error messages from the Log data object. Typically, this option should be checked in the first database part of a sequence of database parts.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Checkbox     | Optional           |
| Skip on error         | When this field is checked the system will skip the execution of subsequent database parts linked to the same Log data object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Checkbox     | Optional           |
| Merge results         | <p>When this field is checked the get records part results will "write into" any stored values for the data-object (for instance from a previous cycle through the part). Any common items are overwritten as expected, but if there are no results from the get records, the prior results will be retained.<br>When not checked, the data-object is cleared of all results prior to running the get records query. In the event there are no results from the get records, the data-object will be empty.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Checkbox     | Optional           |
| Database              | This is the name of the database. It is only used when the data is not stored in the same project and when the location can't be retrieved automatically.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Text         | Optional           |

## Using Advanced SQLite SELECT Statements in Columns

When choosing columns to show from your data table, it is possible to build more complex select statements using SQLite syntax (or other if using another database such as MySQL) . Examples that work with the default SQLite databases include:

* use of sum and count by group
* use of "case when" constructions
* use of || to join two strings (e.g. "USD $"||$(price)
* use of substr to extract partial strings (e.g. select substr(inputdate, 7, 4) as year will select 2020 from the date 06/12/2020)
* use of printf to customize number format (e.g. currency with no decimal places can be shown with select "$" || printf ("%,d",\[cost\_var])

For example, the following statement displays the sum of active hazard cases completed before a particular cutoff date for a particular branch (location) and created in 2018.

```
select sum(case when completed_date<=meeting_date then ifnull(risk_score, 0) else 0 end)
from hazard
where branch_id=$(selected_branch) and status<>'Deleted' and created_date<=meeting_date and created_date>20180000 and item_type='Hazard')
```

For further information on SQLite SELECT statements, refer to <http://www.sqlitetutorial.net/>; however, be aware that db\_grids3 does not support all syntax.

## Examples

Download and import one of the following [example projects](/release-9/example-gallery/example-projects-for-parts/get-records-example-project.md) in your workspace.


---

# 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://community-test.logicnets.com/release-9/platform-documentation/process-node-parts/get-records.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.
