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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:33:55+00:00 2026-05-19T17:33:55+00:00

This is a theoretical question. I’m having trouble defining the question so please bear

  • 0

This is a “theoretical” question.

I’m having trouble defining the question so please bear with me.

When you have several related tables in a database, for example a table that holds “users” and a table that holds “phones”

both “phones” and “users” have a column called “user_id”

select user_id,name,phone from users left outer join phones on phones.user_id = users.user_id;

the query will provide me with rows of all the users whether they have a phone or not.

If a user has several phones, his name will be returned in 2 rows as expected.

columns=>|user_id|name|phone|
row0 = > | 0 |fred|NULL|
row1 = > | 1 |paul|tlf1|
row2 = > | 1 |paul|tlf2|

the name “paul” in the case above is a necessary duplicate which in the RDMS’s eye’s is not a duplicate at all!
It will then be handled by some server side scripting language, for example php.

How are these “necessary duplicates” actually handled in real websites or applications?
as in, how are the row’s “mapped” into some usable object model.

p.s. if you decide to post examples, post them for php,mysql,sqlite if possible.

edit:

Thank you for providing answers, each answer has interpreted the question differently and as such is different and correct in it’s own way.

I have come to the conclusion that if round trips are expensive this will be the best way along with Jakob Nilsson-Ehle’s solution, which was fitting for the theoretical question.

If round trips they are cheap, I will do separate selects for phones and users as 9000 suggests, if I need to show a single phone for every user, I will give a primary column to the phones and join it with the user select like Ollie Jones correctly suggests.

even though for real life applications I’m using 9000’s answer, I think that for this unrealistic question Jakob Nilsson-Ehle’s solution is most appropriate.

  • 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-19T17:33:56+00:00Added an answer on May 19, 2026 at 5:33 pm

    The thing I would probably do in this case in PHP would be to use the userId in a PHP array and then use that to continuosly update the users

    A very simple example would be

    $result = mysql_query('select user_id,name,phone from users left outer join phones on phones.user_id = users.user_id;');
    $users = Array();
    while($row = mysql_fetch_assoc($result)) {
       $uid =$row['user_id'];
       if(!array_key_exists($uid, $users)) {
          $users[$uid] = Array('name' => $row['name'], 'phones' => Array());
       }
       $users[$uid]['phones'][] = $row['phone']; 
    }
    

    Of course, depending on your programming style and the complexity of the user data, you might define a User class or something and populate the data, but that is fundamentally how I would would do it.

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

Sidebar

Related Questions

I have been struggling to find an answer to this theoretical question, even tho
This is a theoretical question; I don't have an actual issue to solve, I
This is a pretty-much theoretical question, but.. How much of an operating system could
This is mostly a theoretical question I'm just very curious about. (I'm not trying
This is a purely theoretical question. Given three simple classes: class Base { }
My question is not exactly the same as this one (it's not theoretical, there
This is a theoretical question, I've already got a solution to my problem that
This is kinda theoretical question, I was looking at someone else' code (below) and
This is a theoretical question, I was wondering if there is a good way
this is just theoretical question. I use JDBC with my Java applications for using

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.