# SQL select Query for report building

**URL:** <https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [October 30, 2020, 9:54pm UTC](https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183 "2020-10-30T21:54:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewcorks](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@andrewcorks](https://forum.inductiveautomation.com/u/andrewcorks)\
**Post date:** [October 30, 2020, 9:54pm UTC](https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183/1 "2020-10-30T21:54:30Z")

</div>

I have a table generated from transaction group tags that writes a new line in the table every time its triggered. I’m trying to build a report table that will list every row from the last 24hrs. I’ve tried several variations of the following code but haven’t had success yet.

SELECT t\_stamp, ProdStr, Total\_panels\_per\_ShiftOrRun, RunEfficency, VolumeSumof38  
FROM mdo\_report  
ORDER BY  
t\_stamp \>= now({[System]Gateway/CurrentDateTime}) AND  
t\_stamp \<= DATE\_SUB(now({[System]Gateway/CurrentDateTime}),INTERVAL 24 HOUR)  
LIMIT 10

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [October 30, 2020, 11:25pm UTC](https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183/2 "2020-10-30T23:25:05Z")

</div>

At a quick glance, you’re using an ORDER BY when it should be a WHERE clause, and also limiting your return to 10 records.

---

<div class="post-metadata">

**Author:** ![andrewcorks](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@andrewcorks](https://forum.inductiveautomation.com/u/andrewcorks)\
**Post date:** [November 2, 2020, 5:45pm UTC](https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183/3 "2020-11-02T17:45:38Z")

</div>

Thanks for the quick response, I still haven’t been able to reach my desired result. For context, this is ultimately what I’m trying to accomplish. I have a table in a vision window that updates on a trigger, adding a new row and I’m trying to create a report that looks like this table. In the vision window I used that data range component instead of the appropriate scripting.  
I didn’t think I’d have to add a new data source for every row in the report builder but I ay need to resort to that if I cant sort this scripting out.

 ![vision window table](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/398815236e39663f6a85a937670a87036ae8448e.png)

Also, when I do post this table in the report build, it only shows one row. I must be missing something simple here. If its relevant, the table is an automatically generated one from a transaction group.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [November 2, 2020, 6:00pm UTC](https://forum.inductiveautomation.com/t/sql-select-query-for-report-building/40183/4 "2020-11-02T18:00:44Z")

</div>

Do you have your start and end dates reversed?  
should be t\_stamp \>= the Date Subtract 24 hours and t\_stamp \<= now
