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

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would say what you have there is more akin… May 11, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer You can use a regular expression (using the re module)… May 11, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer AQTime and dotTrace are two very good commerical profilers. A… May 11, 2026 at 7:06 pm

Related Questions

I have this MySQL query that I'd like to optimize: SELECT min(`topic_id`) FROM `gallery_topics`
Say I have a database of clothing products. In addition to many other fields,
I've got a database with three tables: Books (with book details, PK is CopyID),
I'm having some performance issues in a rails project (running on rails 2.0.5), for
I've only dealt with one-to-one relationships in php so far, but I'm stuck on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.