Author Topic: Insert next id  (Read 413 times)

0 Members and 1 Guest are viewing this topic.

Offline ownerTopic starter

  • Enthusiast
  • Posts: 71
    • View Profile
Insert next id
« on: March 03, 2010, 08:24:05 PM »
Hello,

I am in need of a column where the numbers should be auto incremented if left null, but also allow for duplicate numbers if specified.  Is this possible?  If not, what would be the best way to go about it?  Right now the only way I know I could achieve this is to grab the last inserted id from the last query and then make a second query to update the column of the first one with the same id.

Thanks in advance!
owner

Offline Twister1004

  • Enthusiast
  • Posts: 189
  • Gender: Male
  • PHP 5.5 MySQL 5.5
    • View Profile
Re: Insert next id
« Reply #1 on: March 03, 2010, 08:26:49 PM »
If you are going to use auto increment, then you can NOT have the same number or leave it null. It will call it a duplicate and disregard that SQL. I don't know exactly how to go about your question though.
The world of developing never ceases.

If the time for helping someone comes to this day, wouldn't you be glad to help someone that is trying to?

Offline ownerTopic starter

  • Enthusiast
  • Posts: 71
    • View Profile
Re: Insert next id
« Reply #2 on: March 03, 2010, 08:35:07 PM »
Is there a way to copy the value from an autoincrementing column to the second column without the need of the second query?

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: Insert next id
« Reply #3 on: March 04, 2010, 09:55:17 AM »
Besides, NULL in an auto-increment field will just insert the next number in sequence anyway.

And why would you duplicate information across columns????
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.