# Select last DB entry

**URL:** <https://forum.inductiveautomation.com/t/select-last-db-entry/9656>\
**Category:** Ignition\
**Created:** [February 5, 2015, 12:42am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656 "2015-02-05T00:42:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [February 5, 2015, 12:42am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/1 "2015-02-05T00:42:42Z")

</div>

From the following query, what do I need to add to be able to select the last row only.

Can either be the index number or t\_stamp.

`SELECT ACC_2_Piston_Pressure, Back_Pressure_SP, Back_Pressure_Time, Charged_Volume, Chill_Timer, Extruder_Pressure, Extruder_Temperature, Joint_Cast_Date_Time, Joint_Volume_Used, Lock_Bar_Pressure, Mould_Fill_Time, Purged_Volume, Total_Joint_Time, t_stamp, Joint_Number, Total_Joint_Timer, Mould_Fill_Timer 
FROM impp_logs 
ORDER BY t_stamp DESC`

This is so my report viewer only shows the latest row in the table.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 5, 2015, 12:48am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/2 "2015-02-05T00:48:27Z")

</div>

```auto
SELECT top 1 ACC_2_Piston_Pressure, Back_Pressure_SP, Back_Pressure_Time, Charged_Volume, Chill_Timer, Extruder_Pressure, Extruder_Temperature, Joint_Cast_Date_Time, Joint_Volume_Used, Lock_Bar_Pressure, Mould_Fill_Time, Purged_Volume, Total_Joint_Time, t_stamp, Joint_Number, Total_Joint_Timer, Mould_Fill_Timer
FROM impp_logs
ORDER BY t_stamp DESC

```

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [February 5, 2015, 12:53am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/3 "2015-02-05T00:53:18Z")

</div>

`Error running query:
SQLQuery(query=SELECT top 1 ACC_2_Piston_Pressure, Back_Pressure_SP, Back_Pressure_Time, Charged_Volume, Chill_Timer, Extruder_Pressure, Extruder_Temperature, Joint_Cast_Date_Time, Joint_Volume_Used, Lock_Bar_Pressure, Mould_Fill_Time, Purged_Volume, Total_Joint_Time, t_stamp, Joint_Number, Total_Joint_Timer, Mould_Fill_Timer
FROM impp_logs
ORDER BY t_stamp DESC, database=mobile)@5000ms
On: Logging PDF.Root Container.Report Viewer.IMPP`

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [February 5, 2015, 2:24am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/4 "2015-02-05T02:24:24Z")

</div>

You didn’t say what database you are using. It is different if you are using MySQL or SQL Server.

Try this for MySQL:

```auto
SELECT ACC_2_Piston_Pressure, Back_Pressure_SP, Back_Pressure_Time, Charged_Volume, Chill_Timer, Extruder_Pressure, Extruder_Temperature, Joint_Cast_Date_Time, Joint_Volume_Used, Lock_Bar_Pressure, Mould_Fill_Time, Purged_Volume, Total_Joint_Time, t_stamp, Joint_Number, Total_Joint_Timer, Mould_Fill_Timer
FROM impp_logs
ORDER BY t_stamp DESC
LIMIT 1
```

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [February 5, 2015, 3:26am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/5 "2015-02-05T03:26:29Z")

</div>

A apologies folks, I never knew the code would be different for different databases.

When I was goggling I was searching “SQL last DB entry”. No wonder I was scratching my head for so long as I am indeed using MySQL

Thanks ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:") ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [February 5, 2015, 3:45am UTC](https://forum.inductiveautomation.com/t/select-last-db-entry/9656/6 "2015-02-05T03:45:23Z")

</div>

No problem. Totally understandable. ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")
