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 8777375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:15:52+00:00 2026-06-13T19:15:52+00:00

I have an SQL table with an auto-increment field. I know people have asked

  • 0

I have an SQL table with an auto-increment field. I know people have asked how to retrieve the ID of the ‘last entry’ after the insert has taken place, and I know how to do that. What I want to do is duplicate the auto-generated field in to a second column of the same table – how do I modify my insert code to do this:

mysql_query("INSERT INTO `tags` (`tid`,`tagid`,`tagname`) VALUES('','INSERTED.ID','{$tagname}')");

The reason I want to do this is because I want to be able to make two rows equal each other. I.E. if two different tags (with different unique ids) have the same tagid, then I can use the ‘tagid’ reference elsewhere as a unique identifier and cycle through them. I can also retain knowledge of which tag is the parent tag – because it will have the same ‘tid’ as ‘tagid’.

I have a system for tagging events; but sometimes I miss-spell a tag… so rather than correcting all the mistakes, I want to make my system error proof by allowing miss-spelt tags to be joined up and treated the same way as a the correct tag.

Would appreciate your help – even if that means doing this a completely different way.

Thanks,

  • 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-13T19:15:54+00:00Added an answer on June 13, 2026 at 7:15 pm

    2 options:

    1) You can use LAST_INSERT_ID() mysql function, but in a second query, not in the same.

    SELECT LAST_INSERT_ID();
    

    2) Define a insert Trigger in the table, then when you insert, the trigger “triggers” and do the action in the trigger.

     CREATE TRIGGER tag_tid BEFORE INSERT ON tags
     FOR EACH ROW NEW.tid = NEW.id;
    

    Note: Short creator, see more in the link.

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

Sidebar

Related Questions

I have an table which use an auto-increment field (ID) as primary key. The
I have got a table which has an id (primary key with auto increment),
I have table with several fields, one of them is Id auto-increment/primary field. Is
I have a SQL table BookChapters with over 20 millions rows. It has a
I have a SQL table that has a primary key ( Row_id ) that
I have a Table which has a Primary Key field which is not set
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
I have two SQL statements: CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
I have a SQL table with periodic measurements. I'd like to be able to
I have an sql table containing the gps coordinates of a device, updated every

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.