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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:36:21+00:00 2026-05-20T08:36:21+00:00

I need to do a SELECT in 8 tables, but the results in not

  • 0

I need to do a SELECT in 8 tables, but the results in not what I have expected.

The ugly code:

SELECT equipment.*
FROM equipment
LEFT JOIN equip_adaptador  a ON (a.cod_equip = equipment.cod_equip)
LEFT JOIN equip_antena aa ON (aa.cod_equip = equipment.cod_equip)
LEFT JOIN equip_cable c ON (c.cod_equip = equipment.cod_equip)
LEFT JOIN equip_conector cc ON (cc.cod_equip = equipment.cod_equip)
LEFT JOIN equip_fonte f ON (f.cod_equip = equipment.cod_equip)
LEFT JOIN equip_router r ON (r.cod_equip = equipment.cod_equip)
LEFT JOIN equip_suporte s ON (s.cod_equip = equipment.cod_equip)
WHERE equipment.cod_equip = 'EC726026316A0'

the results is 63 items, is not right.

Explainig the code above:

My table equipment is my master table, there I have the cod_equip field (a master field to all my slave tables).

All my slave table I had gave a prefix called equip_ (are 7 slave tables in the total)

Now I need a SELECT to JOIN all the 8 tables.

Adding more:

I was expecting 9 rows, but it fetched 63 rows, I need to show something like this: table equipment (only 1 row) and other tables the respect number of it owns.

For example equip_adaptador was two times inserted with the same cod_equip, then I need to show it..

This query is the same as if I do one by one query to see what I have with the equipment.cod_equip = ‘EC726026316A0’

Just it!

Thanks in advance people!

  • 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-20T08:36:21+00:00Added an answer on May 20, 2026 at 8:36 am

    What’s happening is that each row returned from a child table is matched with every row returned from the other child tables.

    You have one parent row returned, as you expect.

    But if one of the child tables has seven (7) matching rows, and another child table has nine (9) matching rows, you are getting 7*9=63 rows returned.

    This is the expected resultset, per the SQL specification.

    Here is a test case that demonstrates what is happening:

    CREATE TABLE t (id INT);
    CREATE TABLE c1 (id INT, t_id INT);
    CREATE TABLE c2 (id INT, t_id INT);
    
    INSERT INTO t VALUES (1);
    INSERT INTO c1 VALUES (11,1),(12,1);
    INSERT INTO c2 VALUES (21,1),(22,1);
    
    SELECT t.id, c1.id AS c1, c2.id AS c2
    FROM t
    JOIN c1 ON (t.id = c1.t_id)
    JOIN c2 ON (t.id = c2.t_id)
    
    id  c1   c2
    --  ---  ---
    1   11   21
    1   12   21
    1   11   22
    1   12   22
    

    Note that the rows from c1 are repeated, once for each row from c2. Likewise for the rows from c2.

    This is exactly the result set we expect.

    If we don’t want a cross join (cartesian product) of the child rows, we can run separate queries:

    SELECT t.id, c1.id AS c1
    FROM t
    JOIN c1 ON (t.id = c1.t_id) 
    
    SELECT t.id, c2.id AS c2
    FROM t
    JOIN c2 ON (t.id = c2.t_id)
    
    id  c1
    --  ---
    1   11
    1   12
    
    id  c2
    --  ---
    1   21
    1   22
    

    That’s one way to avoid generating “repeated” child rows.

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

Sidebar

Related Questions

I need to select all columns from two tables, but need to be able
I have a couple of tables and need to join them, but with a
sql select in relation many-to-many not works as expected i have the following tables
I need to select data from 2 tables in my DB - comments and
I select data from several tables. Then i need to edit the data returned
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I have 2 queries which display 2 different values but the results from one
I'm using join to query data from two tables. For each a_id I need
I have two MySQL tables and would like to select the highest value results
Here I have another query bothering me. Select S.ID,S.Name,S.Surname,B.Title,SB.DateAndTimeIssued FROM Students S INNER JOIN

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.