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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:27:38+00:00 2026-05-27T03:27:38+00:00

Possible Duplicate: MySQL Relationships I am trying to create a one to many relationship

  • 0

Possible Duplicate:
MySQL Relationships

I am trying to create a one to many relationship in MySQL with foreign keys.

Two tables, user and location. Each user can have many locations, but each location can have only one user.

How do I configure this? I am using HeidiSQL if that helps, though I can input code as well.

  • 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-27T03:27:39+00:00Added an answer on May 27, 2026 at 3:27 am

    MySQL does not know, nor does it need to know if a relationship is 1-1, or 1-many.
    No SQL supports many-many relationships, all require a intermediate table which splits a many-many relationship into 2 separate 1-many.

    The difference is in the logic that controls the relationships, which is in the code that you write.
    A 1-1 relationship is maintained by having the tables share the same primary key (PK).
    With the secondary table declaring that PK as a foreign key pointing to the other tables PK.

    Table chinese_mother (
    id integer primary key,
    name....
       
    
    Table chinese_child (
    id integer primary key,
    name ....
    ....,
    foreign key (id) references chinese_mother.id
    

    The direction of the relationship 1 -> many vs many <- 1 is determined by the location of the link field.

    Usually every table has a unique id and the link field is called tablename_id.
    The table that has the link field in it is the many side of the relationship, the other table is on the 1 side.

    Each user can have many locations, but each location can have only one user.

    Table user
    id: primary key
    name......
    .....
    
    Table location
    id: primary key
    user_id foreign key references (user.id)
    x
    y
    .......
    

    By placing the link field in the location table, you force things so that a location can only have 1 user. However a user can have many locations.

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

Sidebar

Related Questions

Possible Duplicate: How I can create installer for website. PHP mysql I'm looking to
Possible Duplicate: MySQL returns only one row In Terminal mysql> select image,title,price from test;
Possible Duplicate: MySQL: FULL OUTER JOIN - How do I merge one column? Real
So essentially I have two tables, containing URLS and TAGS, with a has-and-belongs-to-many relationship
Possible Duplicate: Mysql Offset Infinite rows I am trying to get all results for
Possible Duplicate: mySQL - Insert into three tables I want to know if I
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: MySQL number of items within “in clause” In mysql or postgres, is

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.