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.
Selecting a row that was just inserted [Solved]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Selecting a row that was just inserted [Solved]
Last edited by quailcreek on Sat Apr 16, 2016 8:16 pm, edited 1 time in total.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: Selecting a row that was just inserted
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
MacBook Pro OS Mojave 10.14