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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:53:57+00:00 2026-05-11T15:53:57+00:00

I have two tables in my SQL database: Company: ID (autoincrement) name address …

  • 0

I have two tables in my SQL database:

Company:

  • ID (autoincrement)
  • name
  • address
  • …

Employees:

  • ID (autoincrement)
  • Company_id
  • internal_id
  • name
  • lastname

The problem is that I would like to have a employee id (internal_id) that is relative to the company they belong to. I got this dilema since I’m really been searching what would be the cleanest way to implement it.

One option would be to just make a kind of SELECT MAX(internal_id) FROM employees WHERE company_id = X, but the problem would be that if I happen to delete the last employee the next one would be created with the ID of the next.

Any ideas or suggestions?

PD: The reason of why I want to do this is that i dont want a user from company X create an employee that is for example ID=2000, while the last employee created in his company was, say, 1532. this would normally happen in a system in wich Company Y and Z also create employees on the same system. I want this ID not to use as a foreign_key, but to have it for internal (even documents or reports) use.

PD2: In this case the employees will never have to change companies

  • 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. 2026-05-11T15:53:58+00:00Added an answer on May 11, 2026 at 3:53 pm

    There are lots of questions here about creating ‘Business’ IDs or numbers that are unrelated to the primary keys.

    In your case I would create a column on the Company table ‘NextEmployeeID’ Then when creating a new employee simply retrieve the value and increment it.

    Now I leave it up to you to figure out what happens if the employee changes companies. 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • 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 How about: class C(object): blah blah for name in (...):… May 11, 2026 at 7:41 pm
  • Editorial Team
    Editorial Team added an answer It works fine here (I tested it). Are you sure… May 11, 2026 at 7:41 pm
  • Editorial Team
    Editorial Team added an answer I'm inclined toward SLF4J. allows parameterized logging (formatting) allows consolidation… May 11, 2026 at 7:41 pm

Related Questions

I have an internal enterprise application I've developed for my company built on .Net
Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL
I have two databases, one is an MS Access file, the other is a
I have a pretty standard table set-up in a current application using the .NET
I have two tables in my database: NEWS table with columns: id - the

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.