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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:08:12+00:00 2026-05-23T14:08:12+00:00

I have a table named SUBJECT with fields SUBJ_ID and SUBJ_NAME . Another table

  • 0

I have a table named SUBJECT with fields SUBJ_ID and SUBJ_NAME. Another table is called COURSES with the fields COURSE_NAME, SUBJ_NAME, and SUBJ_ID. My goal is to automatically update the SUBJ_ID in the COURSE table with the SUBJ_ID from the SUBJECT table when the SUBJ_NAME is entered into the COURSE table.

For example, the SUBJECT table has the following data:

+-----------+-------------+
| course_ID | course_name |
+-----------+-------------+
|     1     | math        |
|     2     | physics     |
+-----------+-------------+

If I enter into the COURSES table:

INSERT INTO `courses` VALUES('Algebra 101', 'Math');

How can I have it automatically update SUBJ_ID to equal 1?

  • 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-23T14:08:13+00:00Added an answer on May 23, 2026 at 2:08 pm

    Change your table schema to something like below:

    Course Table

    +-----------+---------+------------+
    | course_id | subbj_id|course_name |
    +-----------+---------+------------+
    |     1     | 1       |  math      |
    |-----------+---------+----------- +  
    

    Subject Table

    +-----------+-----------+
    | subj_id   | subj_name |
    +-----------+---------+-+
    |     1     |  math     | 
    |-----------+-----------+
    

    Get rid of the subj_name in the courses table (because its redundant and might lead to data corruption like in your case). This will normalize your data, and you will be able to get the information via joins.

    If you have a subject table with subj_id and subj_name, then the subj_id should be your primary key (unique identifier). Your second table, courses, should have course_id, course_name and subj_id. The course_id should be your primary key (unique identifier). You will then have a one to many foreign key between subj_id in the subject table to subj_id in your course table.

    Once this is set up, you will use this query:

    select c.course_name, s.subj_name from courses AS c inner join subject AS s on c.subj_id = s.subj_id;
    

    This will pull the course and subject that it belongs to.

    When ever you need to update the subject name, you now only have to change it in one place, subject.subj_name, and it will propagate over due to the relationship.

    If all this is too much, read up on normalizing data and setting up relationships properly.

    Best of luck!

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

Sidebar

Related Questions

I have a database table (named Topics) which includes these fields : topicId name
I have a table named CLASS with the Fields **{BATCH, DEGREE, DEPT, SEM, SECTION,
I have a table named Info of this schema: int objectId; int time; int
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have a table named visiting that looks like this: id | visitor_id |
I have a database table named call with columns call_time, location, emergency_type and there
If I have a table field named 'description', what would be the SQL (using
I have a table in my Postgres database with columns named type, desc, and
I have the following MS-Access SQL Table:- NAME, SUBJECT, SCORE ..and I need to
I have a table named t_Student in Microsoft SQL Server 2005 database. In that

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.