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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:33:25+00:00 2026-05-29T09:33:25+00:00

This may be a really simple problem to some people, but I’m finding it

  • 0

This may be a really simple problem to some people, but I’m finding it hard to understand.

The scenario:
I’m working with a school database.
I have a table which relates a class to a subject called ‘subject_class’.

A class can be a part of more than one subject, and a subject can can contain more than one class. So from what I understand, this is a many-to-many relation within a table.

An example of how the database would look:

subject_id          class_id
    1                 14
    1                 15
    2                 14
    *1                *14

As you can see, the same data can be entered into the table more than once (shown above with an asterisk). I want this to stop happening. My question is, what sort of key would this be? and why? or how could I stop the problem from happening?

I hope this makes sense, please let me know if it doesn’t, and I will provide more info.

Thanks in advance.

  • 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-29T09:33:26+00:00Added an answer on May 29, 2026 at 9:33 am

    You would want to have a unique key on subject_id and class_id to prevent duplicates. But you NEED to make sure your application can either: handle the error thrown when you try to insert a value combination that is already there and make try to prevent it from submitting duplicates in the first place.

    Alternatively, if you want the subsequent insert to overwrite the existing entry, you should look into whether your database software can handle ON DUPLICATE KEY UPDATE.

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

Sidebar

Related Questions

OK, this may be really simple, but it is Friday and it has been
This may not really sound hard to do but it is currently killing me.
Okay, This may be really simple or it may not even be possible, or
This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
This may be a duplicate question, but really don't know how else to word
Ok, this may seem like a stupid question (for Flash Developers) but I really
I am a relatively new programmer so this may be a really simple question
Seems like it would be a simple thing really (and it may be), but
this may be a easy question, but I really need a light to go
My problem seems to be really simple but I just can't get the reason

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.