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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:24:48+00:00 2026-06-01T23:24:48+00:00

I have a database of users where I have a primary table with name,

  • 0

I have a database of users where I have a primary table with name, address etc. I then have separate tables for the users children, pets, training courses and education results etc.

This users details can all be displayed on the same page and the way I currently do it is by first querying the database for the users main details. Then I query the other tables individually and display this information with loops.

I really just need to know if this is the best way to do it or whether there is a way of doing it with a single query and if there is any advantage?

The basic structure of the tables is:

+----------------+    +-----------------------+
| Users          |    | Children              |
+----------------+    +-----------------------+
|ID |Name |Age   |    |ID |UserRef |Name |Age |
+----------------+    +-----------------------+
|1  |Jim  |53    |    |1  |1       |Joe  |11  |
|2  |Karl |37    |    |2  |1       |Jane |9   |
+----------------+    |3  |2       |Amy  |15  |
                      +-----------------------+

This is a basic version and only shows the user and children table. The other tables are similar to the children table in that they reference the user table and feature multiple records for a single user.

Thanks 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-01T23:24:50+00:00Added an answer on June 1, 2026 at 11:24 pm

    You could do a simple LEFT JOIN of the tables ON users.id = children.userref. However, since it’s a one-to-many relationship you’d need to use some GROUP BY magic:

      SELECT users.*, GROUP_CONCAT( children.id ORDER BY children.id ASC ) AS childrens_ids, GROUP_CONCAT( children.name ORDER BY children.id ASC ) AS childrens_names, GROUP_CONCAT( children.age ORDER BY children.id ASC ) AS childrens_ages FROM users LEFT JOIN children ON users.id = children.userref GROUP BY children.userref
    

    You’d then have to use code to parse/explode the children’s IDs, names, and ages. Having said all that, though, this isn’t necessarily something you SHOULD do. It’s not necessarily faster on the MySQL end, and you see how much extra work you have to do in your back end code. My recommendation is to try it and see how it affects your performance.

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

Sidebar

Related Questions

I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have a few tables in my database: user table: user_id (primary key) ,
I have three database tables: users emails invitations Emails are linked to users by
I have an existing database with users and administrators in different tables. I am
I have two database tables. One table stores data for a commitment that a
So I have an existing database with a Users table and an Airports table
I already have a User table in my primary application database with an email
I have a database containing users and roles. The table Users has a reference
Does the primary key have to be the first field in a database table?
I have a database with 2 tables: Table 1: CREATE TABLE IF NOT EXISTS

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.