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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:00:56+00:00 2026-06-05T11:00:56+00:00

I have an old registration system, and a new one. (two tables). The old

  • 0

I have an old registration system, and a new one. (two tables).
The old system holds an old category, and the new one holds some new categories that couldn’t be implemented into the old system just yet.
So moving everything to one of the systems is not an option at the moment.

My problem:
I need to connect the two tables so the ID’s operate as “auto increment” and will follow each other somehow.

Here is a scenario:
// table#1 = old system (car)
// table#2 = new system (tractor, truck, marine)

A new car is registered in table#1 and gets the ID : 13579,
then some other vehicle is registered in table#2 and should get the ID : 13580,
and when a new car is registered in table#1 again, it should get ID : 13581.
and so on…

In my mind it goes something like this:
Right before adding the new vehicle into one of the tables, always do a lookup in the other table and check which one is the last/highest ID and do +1 before setting the new ID…

UPDATE 20120614:
Here is one solution I came up with:

$qry_tbl1 = mysql_query('SELECT MAX(id) AS tbl1_max_id FROM tbl1');
$get_tbl1 = mysql_fetch_assoc($qry_tbl1); extract($get_tbl1);

$qry_tbl2 = mysql_query('SELECT MAX(id) AS tbl2_max_id FROM tbl2');
$get_tbl2 = mysql_fetch_assoc($qry_tbl2); extract($get_tbl2);

$new_max_id = max(array($tbl1_max_id,$tbl2_max_id)) + 1;

This is not a good solution, but the only one I got to work.
Immediately after the user hits the submit button, I do this and the INSERT a new record.
Then, further down the script, based on $new_max_id i update that record with additional data…

Is this an acceptable solution?

  • 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-05T11:00:58+00:00Added an answer on June 5, 2026 at 11:00 am

    I think you can use this approach.

    Or you can create new table, with such fields:

    id (auto increment), table_id, table_name

    And save into it table_id – is id for your table entity, table_name – is some attribute, that determines to which table belong this id. During select you have to use this table to determine what id to use. This will avoid id calculations.

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

Sidebar

Related Questions

I have some old files that need to point to new files - the
I have some old branches in my git repository that are no longer under
Hi I am a new one UrlRewriting, I have old urls like http://www.domaine.com/data.aspx http://www.domaine.com/data/page1.aspx
I have a old website that generate its own RSS everytime a new post
I have old code that uses new Date(dateString) to parse a date string. Compiling
I have old code that uses size_t which IIRC comes from cstring.h. On OS
I have and old(ish) C# method I wrote that takes a number and converts
I have an old SQL Server 2000 database that I want to get into
I have an old function that is called many times in my application. I
I have an old asp app I am moving to a new server with

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.