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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:51:14+00:00 2026-06-12T19:51:14+00:00

Quick update — SQLFiddle link: http://sqlfiddle.com/#!2/d038f/2 I think it’s a relatively straight forward one…

  • 0

Quick update — SQLFiddle link: http://sqlfiddle.com/#!2/d038f/2

I think it’s a relatively straight forward one…

I have 7 tables altogether, 3 ‘main’ tables, another 3 that manages the ‘many-to-many’ relationships and another one which is the master table, more precisely:

mysql> show tables;
+--------------------+
| Tables_in_test     |
+--------------------+
| Equipment          |
| Room               |
| Trainer            |
| Training           |
| training_equipment |
| training_room      |
| training_trainer   |
+--------------------+
7 rows in set (0.00 sec)

Now, the schemas and contents:

    mysql> SELECT * FROM Equipment; 
           SELECT * FROM Room; 
           SELECT * FROM Trainer; 
           SELECT * FROM training_equipment; 
           SELECT * FROM training_room; 
           SELECT * FROM training_trainer; 
           SELECT * FROM Training;   



+----+-------------+
| id | equipment   |
+----+-------------+
|  1 | Equipment_1 |
|  2 | Equipment_2 |
|  3 | Equipment_3 |
|  4 | Equipment_4 |
+----+-------------+
4 rows in set (0.00 sec)

+----+--------+
| id | room   |
+----+--------+
|  1 | Room_1 |
|  2 | Room_2 |
+----+--------+
2 rows in set (0.00 sec)

+----+-------+
| id | name  |
+----+-------+
|  1 | John  |
|  2 | Joe   |
|  3 | Jason |
+----+-------+
3 rows in set (0.00 sec)


+-------------+--------------+
| training_id | equipment_id |
+-------------+--------------+
|           1 |            3 |
|           1 |            4 |
|           2 |            1 |
+-------------+--------------+
3 rows in set (0.00 sec)

+-------------+---------+
| training_id | room_id |
+-------------+---------+
|           1 |       1 |
+-------------+---------+
1 row in set (0.01 sec)

+-------------+------------+
| training_id | trainer_id |
+-------------+------------+
|           1 |          2 |
|           1 |          3 |
+-------------+------------+
2 rows in set (0.00 sec)

+----+------------+------------+---------+------+-----------+---+
| id | from       | to         | trainer | room | equipment | a |
+----+------------+------------+---------+------+-----------+---+
|  1 | 1349578297 | 1350096689 |       1 |    1 |         1 | 0 |
+----+------------+------------+---------+------+-----------+---+
1 row in set (0.02 sec)

I came up with the following query and you can see that the result is not correct:

mysql> SELECT t.from, r.room, tra.name, e.equipment
    -> FROM Training t
    -> LEFT JOIN training_room tr ON ( t.room = tr.training_id )
    -> LEFT JOIN Room r ON ( tr.room_id = r.id )
    -> LEFT JOIN training_trainer tt ON ( t.trainer = tt.training_id )
    -> LEFT JOIN Trainer tra ON ( tt.trainer_id = tra.id )
    -> LEFT JOIN training_equipment te ON ( t.equipment = te.training_id)
    -> LEFT JOIN Equipment e ON ( te.equipment_id = e.id )
    -> WHERE t.id =1;
+------------+--------+------+-------------+
| from       | room   | name | equipment   |
+------------+--------+------+-------------+
| 1349578297 | Room_1 | Joe  | Equipment_3 |
| 1349578297 | Room_1 | Joe  | Equipment_4 |
| 1349578297 | Room_1 | Jason| Equipment_3 |
| 1349578297 | Room_1 | Jason| Equipment_4 |
+------------+--------+------+-------------+
4 rows in set (0.02 sec)

I don’t want to see duplicate results, all I’d like to see would be:

+------------+--------+------+-------------+
| from       | room   | name | equipment   |
+------------+--------+------+-------------+
| 1349578297 | Room_1 | Joe  | Equipment_3 |
| 1349578297 | Room_1 | Jason| Equipment_4 |
+------------+--------+------+-------------+

DISTINCT doesn’t solve the problem nor does GROUP BY tra.name, e.equipment

Thank you.

  • 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-12T19:51:15+00:00Added an answer on June 12, 2026 at 7:51 pm

    Sorry, but with your current database structure, i think there’s no query to match your requirement.
    But you can check the group_concat() function, it can group the equipment and trainer name into a string. and then you can extract the value by use server code like php.

     SELECT t.from, r.room, group_concat(distinct tra.name), group_concat( distinct e.equipment)
     FROM Training t
     LEFT JOIN training_room tr ON ( t.room = tr.training_id )
     LEFT JOIN Room r ON ( tr.room_id = r.id )
     LEFT JOIN training_trainer tt ON ( t.trainer = tt.training_id )
     LEFT JOIN Trainer tra ON ( tt.trainer_id = tra.id )
     LEFT JOIN training_equipment te ON ( t.equipment = te.training_id)
     LEFT JOIN Equipment e ON ( te.equipment_id = e.id )
     WHERE t.id =1
    

    If you can change the structure of table “training_equipment”, add another column “trainer_id” then you can use the query below:

    SELECT t.from, r.room, tra.name, e.equipment
    FROM Training t
    LEFT JOIN training_room tr ON ( t.room = tr.training_id )
    LEFT JOIN Room r ON ( tr.room_id = r.id )     
    LEFT JOIN training_equipment te ON ( t.equipment = te.training_id)
    LEFT JOIN Equipment e ON ( te.equipment_id = e.id )
    LEFT JOIN Trainer tra ON ( te.trainer_id = tra.id )
    WHERE t.id =1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a realy quick question One way to update or insert data in
Is there a quick and easy way to update my LINQ dbml files? Right
Hey guys quick question, I want to update the contents of a div with
Quick method description: I have two tables, lets name them table ONE and table
I need a quick no for DELETE/UPDATE/INSERT, since 3p reporting tool allows users to
Possible Duplicate: How to update Linq to SQL dbml file? Is there a quick
UPDATE 14 June 2011 A quick update... Most respondents have focused on the dodgy
I made the error of running what should have been a quick update against
Just a quick one really, I'm just looking for a bit of clarification. I'm
UPDATE : Thanks for all the quick responses. Should have probably clarified that I've

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.