Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL double LEFT OUTER JOIN
    primarykey
    data
    text
    <h1>Into</h1> <p>I have two tables <strong>profile</strong> and <strong>name</strong>, the profile table contains some metadata relating to a user. The name table contains all the possible names the profile could have.</p> <p>I am trying to create a <strong>MYSQL</strong> query that will give me the profile.age, the given name and family name for all profiles even if that dont have a given name or family name</p> <h1>Tables</h1> <h2>Profile</h2> <pre> +-------+---------+ | ID | AGE | +-------+---------+ | 0 | 10 | | 1 | 20 | | 2 | 30 | | 3 | 40 | +-------+---------+ </pre> <h2>Name</h2> <pre> +------------+--------+--------+ | PROFILE_ID | TYPE | NAME | +------------+--------+--------+ | 0 | 0 | Jo | | 0 | 1 | Blog | | 1 | 0 | Jim | | 2 | 1 | Smith | +------------+--------+--------+ Type 0 = Given Name Type 1 = Family Name </pre> <h1>Quert</h1> <p>This is the Query I am currently using.</p> <pre><code>SELECT given.name AS 'given_name', family.name AS 'family_name', profile.age FROM profile LEFT OUTER JOIN name given ON profile.id = given.profile_id LEFT OUTER JOIN name family ON profile.id = family.profile_id WHERE given.type = 0 AND profile_id.type = 1 LIMIT 0 , 30 </code></pre> <h1>Problem</h1> <p>This is the result I want and expect to get</p> <pre> +------------+-------------+--------+ | GIVEN_NAME | FAMILY_NAME | ADE | +------------+-------------+--------+ | Jo | Blog | 10 | | Jim | NULL | 20 | | NULL | Smith | 30 | | NULL | NULL | 40 | +------------+-------------+--------+ </pre> <p>However this is what I actually get</p> <pre> +------------+-------------+--------+ | GIVEN_NAME | FAMILY_NAME | AGE | +------------+-------------+--------+ | Jo | Blog | 10 | +------------+-------------+--------+ </pre> <p>From what I understand <strong>LEFT OUTER JOIN</strong> should return on the NULL value joins. What am I doing wrong? How do I change my Query to return the NULL value joun?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload