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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:30:44+00:00 2026-05-13T10:30:44+00:00

I have a table that stores records and already has primary key. Table A

  • 0

I have a table that stores “records” and already has primary key.

Table A
=======
id (INT) PK auto_increments
project_id (INT)
record_text (TEXT)

This table stores “records” for all of my projects. It is desirable to have a secondary key that auto increments for the projects.

Example: If project 1 had id’s of (1,5,8,9). It would be desirable to store them and present them to the user as (1,2,3,4).

I do not have the ability to use TRANSACTIONS and I’m having trouble thinking of a way of doing this without causing concurrency issues.

Hopefully I got my problem across clearly. Thank you in advance for the help.

Edit (Example):
Assuming the structure:
id, project_id, record text
1 1 testing
2 1 testing
3 2 testing
4 1 testing

My ID’s for project 1 would 1,2,4. But I’m looking for a way to store and display them for project 1 as 1,2,3

  • 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-13T10:30:44+00:00Added an answer on May 13, 2026 at 10:30 am

    I’m not sure what I was thinking, too late in the day probably, but I was able to achieve this by adding a column to the table:

    id, pid, project_id, record_text
    

    pid being the numbering system for the project.

    The INSERT:

    INSERT INTO A (id, pid, project_id, record_text) 
    VALUES (
        NULL, 
        (SELECT COALESCE(new_id, 0) + 1 FROM (SELECT MAX(new_id) AS new_id FROM atest WHERE project_id = 1) AS x),
        1,
        'some text'
    );
    

    Now as my project changes my pid, id based off the project, auto-increments too:

    id    pid    project_id    record_text
    1     1      1             testing 123
    2     2      1             testing 123
    3     1      2             testing 123
    4     3      1             testing 123
    

    Thank you all for your input and I apologize for my poor description of the problem.

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

Sidebar

Related Questions

I have a table that stores records like this: name | stat | value
I have a table that stores data that has been entered regarding the amount
I have a table that stores user information. The table has a userid (identity)
I have mysql table that has a column that stores xml as a string.
I have a Pages table that stores all my view urls and this table
I have a MSSQL table stores that has the following columns in a table:
I currently have a table that is 17 columns wide and has 30 records.
I have a table that has about 1/2 million records in it. Each month
I have a table that stores email in 3 diffrent columns name host and
I have a table that stores various clients I have done work for, separated

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.