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

  • Home
  • SEARCH
  • 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 190221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:14:16+00:00 2026-05-11T16:14:16+00:00

In my table (MySQL) I have these fields: id – primary, auto_increment hash –

  • 0

In my table (MySQL) I have these fields:

id – primary, auto_increment

hash – base 36 representation of id

I’d like to populate both fields at once, using a stored procedure to compute the base 36 equivalent of the value id receives on INSERT. Something like this:

INSERT into `urls` (`id`,`hash`) VALUES (NULL,base36(`id`));

Obviously this doesn’t work, but I hope it illustrates what I’m trying to achieve. Is this possible, and if so, how?

Note: I want to use only one query, so last_insert_id isn’t helpful (at least as I understand).

  • 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-05-11T16:14:16+00:00Added an answer on May 11, 2026 at 4:14 pm

    This question is essentially a restatement of this other one. In a nutshell, the advantage of an auto increment field is that the value is guaranteed unique, the disadvantage is that the value doesn’t exist until the INSERT has already been executed.

    This is necessarily the case. You can, for example, retrieve for a given table what the next auto increment value will be, but because of concurrency concerns, you can’t be sure that the query you execute next will be the one that gets that ID. Someone else might take it first. The assignment of the ID field has to be, therefore, an atomic get-and-increment operation that happens as the record is being inserted.

    In other words, though you may want to do this in a single query, you’re simply not going to. There’s a way you could theoretically pretend that you’re only executing one query by attaching a trigger on INSERT that adds your alternate representation of the ID field after the fact. Alternately, you can use a non-auto-increment ID field based on something known ahead of time.

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

Sidebar

Related Questions

I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have a table in MySQL that has 3 fields and I want to
If I have a table in MySQL which represents a base class, and I
I have two table fields in a MySQL table. One is VARCHAR and is
I have a MySQL table where there are two fields that make up the
I have a table my_table with these fields: id_a, id_b. So this table basically
I have a mysql table and one of the fields is 'template'. This field
I have a MySQL table with approximately 3000 rows per user. One of the
I have a MySQL table containing domain names: +----+---------------+ | id | domain |
I have a mysql table that relies on the unix epoch time stamp equivalent

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.