Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:35+00:00 2026-06-12T00:12:35+00:00

On my db-server i am inserting data in a table having a auto increment

  • 0

On my db-server i am inserting data in a table having a auto increment field say ‘id’. Now i want to use the value of this last inserted ‘id’ in subsequent steps. I can use this:-

  select * from table_name order by id desc limit 1; 

But the problem here is, it is a server and many more insertions could be happening and there could be a case where i try to retrieve the data with the query i mentioned and get a different id ie. between my insert and select there could be some other insert and i wont get the value i inserted. Any way in which this could be addressed.?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:12:37+00:00Added an answer on June 12, 2026 at 12:12 am

    Use this

    mysql_insert_id(&mysql);  
    

    as its basic structure are

    mysql_insert_id ([ resource $link_identifier = NULL ] )
    

    Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).

    or in mysql use

       SELECT LAST_INSERT_ID();
    

    here is the ref links

    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

    http://php.net/manual/en/function.mysql-insert-id.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble inserting data into a table. I have the following tables: track
This is a private message system. It should be inserting data into the table,
I'm having trouble inserting image data into my database. I have a table called
I want that as a user is inserting data into a table, he is
Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data
I am having trouble inserting values into my Account table that's in a SQL
Using SQL Server 2000 Master Table ID Date Value 001 23-04-2009 200 001 24-04-2009
This is a simple example. I want to insert data in Table1 (Name, Age,
I got table with 3 columns (Primary)id, type, name. I am inserting data into
I'm using entity framework 4.1 (VS 2010, SQL Server 2012) for inserting data into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.