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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:14:23+00:00 2026-05-31T19:14:23+00:00

I´m using Mysql since quite a while and am really confused by the result

  • 0

I´m using Mysql since quite a while and am really confused by the result of a simple LEFT JOIN on three Tables.

I have the following three tables (I created an example, to narrow it down)

a) persons

+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| PersonID | int(11)     | NO   | PRI | NULL    | auto_increment |
| Name     | varchar(50) | YES  |     | NULL    |                |
| Age      | int(11)     | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+

b) person_fav_artists

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| FavInterpretID | int(10)      | NO   | PRI | NULL    | auto_increment |
| PersonID       | int(10)      | NO   |     | 0       |                |
| Interpret      | varchar(100) | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+

c) person_fav_movies

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| FavMovieID | int(10)      | NO   | PRI | NULL    | auto_increment |
| PersonID   | int(10)      | NO   |     | 0       |                |
| Movie      | varchar(100) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

My example tables are used to store an any number of artists and movies to a single person.
Weather this makes sence or not doesn´t really matter since it´s just a simple example.

Now I have the following data in the tables:

mysql> SELECT * FROM persons;
+----------+------+------+
| PersonID | Name | Age  |
+----------+------+------+
|        1 | Jeff |   22 |
|        2 | Lisa |   15 |
|        3 | Jon  |   30 |
+----------+------+------+

mysql> SELECT * FROM person_fav_artists;
+----------------+----------+----------------+
| FavInterpretID | PersonID | Interpret      |
+----------------+----------+----------------+
|              1 |        1 | Linkin Park    |
|              2 |        1 | Muse           |
|              3 |        2 | Madonna        |
|              4 |        2 | Katy Perry     |
|              5 |        2 | Britney Spears |
|              6 |        1 | Fort Minor     |
|              7 |        1 | Jay Z          |
+----------------+----------+----------------+

mysql> SELECT * FROM person_fav_movies;
+------------+----------+-------------------+
| FavMovieID | PersonID | Movie             |
+------------+----------+-------------------+
|          1 |        1 | American Pie 1    |
|          2 |        1 | American Pie 2    |
|          3 |        1 | American Pie 3    |
|          4 |        3 | A Game of Thrones |
|          5 |        3 | Eragon            |
+------------+----------+-------------------+

Now i´m simply joining the tables with the following query:

Select * FROM persons
LEFT JOIN person_fav_artists USING (PersonID)
LEFT JOIN person_fav_movies USING (PersonID);

which returns the following result:

+----------+------+------+----------------+----------------+------------+-------------------+
| PersonID | Name | Age  | FavInterpretID | Interpret      | FavMovieID | Movie             |
+----------+------+------+----------------+----------------+------------+-------------------+
|        1 | Jeff |   22 |              1 | Linkin Park    |          1 | American Pie 1    |
|        1 | Jeff |   22 |              1 | Linkin Park    |          2 | American Pie 2    |
|        1 | Jeff |   22 |              1 | Linkin Park    |          3 | American Pie 3    |
|        1 | Jeff |   22 |              2 | Muse           |          1 | American Pie 1    |
|        1 | Jeff |   22 |              2 | Muse           |          2 | American Pie 2    |
|        1 | Jeff |   22 |              2 | Muse           |          3 | American Pie 3    |
|        1 | Jeff |   22 |              6 | Fort Minor     |          1 | American Pie 1    |
|        1 | Jeff |   22 |              6 | Fort Minor     |          2 | American Pie 2    |
|        1 | Jeff |   22 |              6 | Fort Minor     |          3 | American Pie 3    |
|        1 | Jeff |   22 |              7 | Jay Z          |          1 | American Pie 1    |
|        1 | Jeff |   22 |              7 | Jay Z          |          2 | American Pie 2    |
|        1 | Jeff |   22 |              7 | Jay Z          |          3 | American Pie 3    |
|        2 | Lisa |   15 |              3 | Madonna        |       NULL | NULL              |
|        2 | Lisa |   15 |              4 | Katy Perry     |       NULL | NULL              |
|        2 | Lisa |   15 |              5 | Britney Spears |       NULL | NULL              |
|        3 | Jon  |   30 |           NULL | NULL           |          4 | A Game of Thrones |
|        3 | Jon  |   30 |           NULL | NULL           |          5 | Eragon            |
+----------+------+------+----------------+----------------+------------+-------------------+
17 rows in set (0.00 sec)

So far so good.
My question is now if it´s “normal” that ’12’ Rows are returned for the person ‘Jeff’ despite the fact that he only has four ‘artists’ and three ‘movies’ assigned to him.
I think I may understand why the result is as it is, but I think it´s quite stupid to return so many Rows for so less actual data.

So is there something wrong with my query or is this behaviour on purpose?

The result I´d like to have would be like the following (only for Jeff):

+----------+------+------+----------------+----------------+------------+-------------------+
| PersonID | Name | Age  | FavInterpretID | Interpret      | FavMovieID | Movie             |
+----------+------+------+----------------+----------------+------------+-------------------+
|        1 | Jeff |   22 |              1 | Linkin Park    |          1 | American Pie 1    |
|        1 | Jeff |   22 |              2 | Muse           |          2 | American Pie 2    |
|        1 | Jeff |   22 |              3 | Fort Minor     |          3 | American Pie 3    |
|        1 | Jeff |   22 |              4 | Jay Z          |          1 | NULL              | <- 'American Pie 1/2/3' would be OK as well.
+----------+------+------+----------------+----------------+------------+-------------------+

Thanks for your help!

  • 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-31T19:14:24+00:00Added an answer on May 31, 2026 at 7:14 pm

    You are getting the correct result with the 12 records becuase that is the correct tuple with the way you are asking for the data. I am not sure why you are joinming these 3 tables together becuase inherently, the 2 related tables are not the same type of data. What I would suggest is that you select person & movies and then you can union person & artists, becuase your union will want the columns to be the same, i would suggest adding a type to differentiate from artists and movies and then the nice name should just be AS a string_value

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

Sidebar

Related Questions

Using MySQL, I have three tables: projects : ID name 1 birthday party 2
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
I have been making HTML/PHP/MySQL database apps for quite a while now. I have
I'm using MySQL to store video game data. I have tables for titles, platforms,
Using MySQL syntax, how would I write a query to return the following (I
(Using MySQL and PHP) I have a search form that will allow my users
I am using MySQL and PHP for a project I am working. I have
We are using MySQL version 5.0 and most of the tables are InnoDB. We
I've run into a problem when using SubSonic 3(.0.0.3) ActiveRecord with MySQL. Since MySQL
I'm building a system using django, Sphinx and MySQL that's very quickly becoming quite

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.