Selecting a row that was just inserted [Solved]

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Selecting a row that was just inserted [Solved]

Post by quailcreek » Fri Apr 15, 2016 1:26 am

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.
Last edited by quailcreek on Sat Apr 16, 2016 8:16 pm, edited 1 time in total.
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Selecting a row that was just inserted

Post by quailcreek » Sat Apr 16, 2016 8:15 pm

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
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “Databases”