# SQL Scripting For Tables

**URL:** <https://forum.inductiveautomation.com/t/sql-scripting-for-tables/93094>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [July 11, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/sql-scripting-for-tables/93094 "2024-07-11T16:04:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [July 11, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/sql-scripting-for-tables/93094/1 "2024-07-11T16:04:55Z")

</div>

I am creating an SQL query, I have the the following types of values

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f56a835dabdfd6715b76dc80493b4e49936f528c.png)

I would like to filter by the largest "id", I want to only show the top 5 largest "id" values, and display only the eventtime and the source on the table.

My current query that exclusively displays all of the values for each column is below.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/18ded2731441069b2e9555d03e9faf9008143130.png)  
I had worked on this for a while, but continue to write SQL scripts that yield no data.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 11, 2024, 4:41pm UTC](https://forum.inductiveautomation.com/t/sql-scripting-for-tables/93094/2 "2024-07-11T16:41:15Z")

</div>

What is the database?

For MariaDB/MYSql something like this should work:

```python
SELECT source,eventtime FROM alarm_events ORDER BY id DESC LIMIT 5

```

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [July 11, 2024, 4:45pm UTC](https://forum.inductiveautomation.com/t/sql-scripting-for-tables/93094/3 "2024-07-11T16:45:31Z")

</div>

As @bschroeder suggested. An `ORDER BY` with a row limit would work. Depending on the DB flavor, the syntax for the row limit will differ. See this page for examples: [SQL SELECT TOP, LIMIT, ROWNUM](https://www.w3schools.com/sql/sql_ref_select_top.asp).
