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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:15:43+00:00 2026-06-10T15:15:43+00:00

Quick question about the most efficient was to handle this, I have a database

  • 0

Quick question about the most efficient was to handle this, I have a database which has a tree structure of user types,

system ---  1 to m --- account --- 1 to m --- customer  

All three types can have multiple email addresses, I was wondering what would be the best way to handle this in a database, all user types have auto_id as their primary key so having a table with address identified by there related primary key wont work as there will be potentially 3 of each. e.g. email with key 2 , will link to system with id 2 , account with id 2 , etc.

Should I create a table of email addresses for each type .? Or is there a more elegant solution .?

Thanks

  • 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-10T15:15:44+00:00Added an answer on June 10, 2026 at 3:15 pm

    You either have an email table that has a foreign key which is either a system_id, account_id, or customer_id. Then you can have a field specifying the type of that foreign key. Another more complicated strategy would be to have still the email table but no foreign key. Another table which you would call email_relation consisting of the email_id and the foreign key. That way you could use one e-mail address for all three tables.

    Example of the use of two tables

    system
    --------
    s1 
    s2
    s3
    
    account
    --------
    a1
    a2
    a3
    
    customer
    --------
    c1
    c2
    c3
    
    email
    ------
    e1 example1@a.com
    e2 example2@a.com
    e3 example3@a.com
    e4 example4@a.com
    
    email_relation
    ---------------
    email_id     foreign_id      relation_type
    e1           s1              system
    e1           a1              account
    e1           c1              customer
    e2           c1              customer
    e3           c2              customer
    e4           a3              account
    e4           c3              customer
    

    if you want the customer table including the e-mail address

    select c.customer_id, e.email
    from customer c
    left join email_relation r on (r.foreign_id = c.customer_id and relation_type = 'customer')
    left join email          e on (e.email_id    = r.email_id)
    where r.email_id is not null
    

    If you want all e-mail to a system you could also

    select e.email
      from email e
      join email_relation r on (r.email_id = e.email_id and relation_type = "system")
     where r.foreign_id = 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question about database design. If I have two databases: User_DB and Group_DB, and
I have a very quick question about how to utilise Zend_Db_Table with user specific
Quick question about include/requre_once . I have some code that is common to a
I have a quick question about something I imagine must be pretty easy -
I have a quick question about ARC in iOS. (Sorry I've asked so many
I have quick question about text parsing, for example: INPUT=a b c d e
Quick question about the TransactionScope object. Found this on the internet: When you access
Just a quick question about my Domain Layer/ Domain Service... Should I allow this
Quick question about unit testing. My application has a few embeded Xml files, they
I have a quick question about namespace scope: I have two namespaces, A and

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.