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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:34:08+00:00 2026-06-09T12:34:08+00:00

I have a table called countries that has the structure: ID, LOCALES_ID, NAME I

  • 0

I have a table called countries that has the structure: ID, LOCALES_ID, NAME

I want to handle multiple locales with this table, so I need that for different LOCALES_ID, the ID is the same. So, if I insert:

INSERT INTO countries (locales_id, name)
VALUES
('1', 'Lorem'),
('2', 'Ipsum');

The final result I want on the database is:

ID | LOCALES_ID | NAME
1  | 1          | Lorem
1  | 2          | Ipsum

But with the INSERT I tried I got the next result:

ID | LOCALES_ID | NAME
1  | 1          | Real insert
2  | 2          | Real insert #2

My countries table has a PRIMAY index on the columns ID and LOCALES_ID and I supposed that this was all what I need for when I insert different locales I get the same ID.

How I can solve this problem?

Thank you 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-06-09T12:34:09+00:00Added an answer on June 9, 2026 at 12:34 pm

    What you’re trying to implement here is a one-to-many relationship, i.e. each Country can have multiple Locales. This cannot be achieved with a single table, as you would find yourself with the same Country appearing multiple times. What you should do is split the data in two tables. You can find an example below.

    Structure for Countries table
    – ID int, autoincrement, primary key
    – Name varchar

    Structure for Locales table
    – CountryID int, primary key
    – LocaleID int, primary key
    – Name varchar

    Handling INSERT
    – To insert in Countries table, simply populate Name field (or any other fields you may need):

    INSERT INTO Countries
      (Name)
    VALUES
      ('Ireland')
    

    The ID field will be populated automatically. For this example, we can imagine that “Ireland” will have ID = 1.
    – To insert in Locales, you’ll pass three values, i.e. CountryID, LocaleID and Name.

    INSERT INTO Locales
      (CountryID, LocaleID, Name)
    VALUES
      (1, 1, 'Lorem')
    

    This query will insert LocaleID for the Country with ID = 1 (i.e. Ireland) and ‘Lorem’ as a name. To insert ‘Ipsum’, you’ll do the same:

    INSERT INTO Locales
      (CountryID, LocaleID, Name)
    VALUES
      (1, 2, 'Ipsum')
    

    Where LocaleID will be 2, for Country with ID = 1 and name will be ‘Ipsum’.

    How to retrieve the data
    Since now data is split in two tables, you’ll have to use a Join to put it together. It’s very simple:

    SELECT
      C.ID AS CountryID
      ,L.Name AS CountryName
      ,L.LocaleID
    FROM
      Countries C
      LEFT JOIN
      Locales L ON
        (L.CountryID = C.CountryID) AND
        (L.LocaleID = :InputLocaleID)
    

    That’s it. Now your query will return the Country with its name in the proper Locale, if it exists. If it doesn’t, CountryName and LocaleID will be NULL.

    Update 2012/08/11 – How to use a single table (not recommended)

    If you wish to use a single table for the Countries, you’ll have to handle the Country IDs manually. That is, you’ll perform an INSERT as follows:

    INSERT INTO Countries
      (ID, LocaleID, Name)
    VALUES
      (:CountryID, :LocaleID, :Name)
    

    This, however, will leave you with an issue. Imagine the table contains an unspecified number of Countries and you have to add a new one. What ID would you give to this new Country?

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

Sidebar

Related Questions

I have a table called user_details this table has got morethan 100k user details
I have a table called Shoppings in my SQL db. This one has a
I have table called 'shipped_data' https://i.stack.imgur.com/JXBej.png and need go get all 'caseNumbers' that match
i have table called as Support, which have a field named Name and contains
I have table called posts in my DB. Each post has field called social_network
I have a table called 'MyTable' that looks like: ID | Item | Type
I have a table called 'survey_product' with the following structure: id int(11) order_id int(11)
I have two tables, one called countries and one called country. Countries has both
I have table called Direccion other called Cliente each one defined like this public
I have a table called employee with following fields Id | Name | PrimaryEmail1

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.