Page 1 of 1

Selecting a row that was just inserted [Solved]

Posted: Fri Apr 15, 2016 1:26 am
by quailcreek
Hi,
Is there a "semi-automated" way, using some SQL trickery, of selecting the last row inserted into a table? Is there a way to using SELECT COUNT(column_name) FROM table_name? It will return the row count as long as there aren't any null values. I need to select a column in a row that was just inserted. Not a problem if there are only a few rows but that doesn't happen very often. Thanks for help.

Re: Selecting a row that was just inserted

Posted: Sat Apr 16, 2016 8:15 pm
by quailcreek
I figured this out. Here's what I ended up with in case anybody else need to do the same thing.

Code: Select all

function getLastBarcode
   constant kSelect="SELECT COUNT(itemBarcode) FROM purchasedItems"
   put revDataFromQuery(,,the uDatabaseID of this stack,kSelect) into theRowCount
   
   constant aSelect="SELECT itemBarcode FROM purchasedItems WHERE rowID=:1"
   put revDataFromQuery(,,the uDatabaseID of this stack ,aSelect,"theRowCount") into theBarcode
   
   return theBarcode
end getLastBarcode