Select Last Number In Access

I have recently been working on a ticketing system and i needed to know how to find they next number for the primary key. Took me a while to find out how to do it in access so i thought i would share it.

Here is this SQL that i used.

SELECT LAST([Tickets.TicketID])+1 AS TicketID FROM Tickets

I know that with many of the better DBMS they can return the generated keys, But from what i found you can not do this with access.

If you have found any easier methods then please feel free to share them.

Comments
dfsaf's Gravatar Use an autonumber column. It gets set automatically instead of you getting it first.
# Posted By dfsaf | 07/03/09 13:57
Jonny Shaw's Gravatar I needed to insert to 2 tables at the same time. I needed to know the TicketID from the 1st table to use it in the second.
But as i said in the post MS access wont allow you to return generated keys.
# Posted By Jonny Shaw | 07/03/09 14:10
Andrew Scott's Gravatar My question is simple, why MS Access?

Access is maybe better these days than it was many years ago. But there are far better databases to use than MS Access. Hell Coldfusion 8 comes with Derby and you can use other free DB's like mySQL or MS SQL Express to name a few.

It still amazes me why people still use MS Access, I see no good reason for it.
# Posted By Andrew Scott | 07/03/09 21:19
Jonny Shaw's Gravatar I was using it with a java application.
The only reason i used access was because it was a requirement in the specification.
I would have probably used oracle if it were up to me.
# Posted By Jonny Shaw | 08/03/09 23:24
dave's Gravatar If you use the autonumber column you can do a select max(id) from firsttable after you've done the insert to get the number you need for the second table, just do the insert and select inside a cftransaction
# Posted By dave | 06/04/09 19:26
Jonny Shaw's Gravatar I wasnt using coldfusion, i was using java
# Posted By Jonny Shaw | 06/04/09 19:36
Todd Rafferty's Gravatar Make one more column, insert a createuuid() into that column.. do a selection to get the id of the column where create_uuid = #the_uuid_you_just_inserted#.

Otherwise, you'll run into issues using this code when multiple people start using it.
# Posted By Todd Rafferty | 05/08/09 23:18
Jonny Shaw's Gravatar It will work fine if it is done in a transaction
# Posted By Jonny Shaw | 05/08/09 23:22
Reagan's Gravatar With the help of Rapidshare Search engine( http://www.rapidsharemix.com/trends/cz/08-04-2010.... ) you can search all rapid share files easily
# Posted By Reagan | 09/04/10 17:58
nike air max shoes's Gravatar Free shipping buy coach handbags in coach outlet online,save up 76%,[url=http://www.coachhandbags-onsale.us/]coach handbags on sale[/url],2010 new style ugg snow boots cheap sale,[url=http://www.uggbootsallhere2.com/]cheap ugg boots[/url]

Nike air max 2010,air max 2009,air max shoes on sale.Buy nike air max shoes on http://www.nikeairmax-1.com low at $62,especially [url=http://www.nikeairmax-1.com/]air max 2010[/url],[url=http://www.nikeairmax-1.com/]air max 2009[/url],BOSE products include BOSE headphones,BOSE mobile in-ear, Bose earphones headphones [url=http://www.headphoneonsales.com/]cheap bose headphones[/url][url=http://www.headphoneonsales.com/]bose headphones[/url]
# Posted By nike air max shoes | 02/09/10 07:30
coach handbags's Gravatar These four pairs are all from Sergio Rossi. And their color is all can match well with your wedding dress, and make you look more charming when you wear them,[url=http://www.mychristianlouboutinshoes.com/blog]christian louboutin shoes [/url],[url=http://www.mychristianlouboutinshoes.com/cheap-chr...]cheap christian louboutin[/url],[url=http://www.mychristianlouboutinshoes.com/christian...]christian louboutin boots[/url],[url=http://www.mychristianlouboutinshoes.com/christian...]christian louboutin pumps[/url],[url=http://www.mychristianlouboutinshoes.com/christian...]christian louboutin shoes[/url],[url=http://www.christian-louboutin-sale.us/]christian louboutin sale[/url],[url=http://www.christian-louboutin-sale.us/]cheap christian louboutin[/url]
# Posted By coach handbags | 02/09/10 07:30

Archives By Subject

Advertising (4) [RSS]
Blog Design (1) [RSS]
CFProject Scripts (2) [RSS]
Coldfusion Charts (3) [RSS]
Coldfusion Functions (5) [RSS]
Coldfusion Overview (1) [RSS]
Coldfusion Tutorials (16) [RSS]
For Sale (2) [RSS]
Image Manipulation (1) [RSS]
Java (1) [RSS]
JavaScript (4) [RSS]
PHP (1) [RSS]
Railo (4) [RSS]
SQL (1) [RSS]
Useful Tools (3) [RSS]

Recent Comments

Coldfusion and Java
nike air max shoes said: Free shipping buy coach handbags in coach outlet online,save up 76%,[url=http://www.coachhandbags-...... [More]

Coldfusion and Java
coach handbags said: These four pairs are all from Sergio Rossi. And their color is all can match well with your wedding ... [More]

Select Last Number In Access
coach handbags said: These four pairs are all from Sergio Rossi. And their color is all can match well with your wedding ... [More]

Select Last Number In Access
nike air max shoes said: Free shipping buy coach handbags in coach outlet online,save up 76%,[url=http://www.coachhandbags-...... [More]

Unlimited Website Hosting
nike air max shoes said: Free shipping buy coach handbags in coach outlet online,save up 76%,[url=http://www.coachhandbags-...... [More]

Recent Entries

No recent entries.
ColdFusion Blog | ColdFusion Hosting | ColdFusion Q & A