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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:05:10+00:00 2026-05-28T13:05:10+00:00

Into I have two tables profile and name , the profile table contains some

  • 0

Into

I have two tables profile and name, the profile table contains some metadata relating to a user. The name table contains all the possible names the profile could have.

I am trying to create a MYSQL 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

Tables

Profile


    +-------+---------+
    | ID    | AGE     | 
    +-------+---------+
    | 0     |  10     |
    | 1     |  20     |
    | 2     |  30     |
    | 3     |  40     |
    +-------+---------+  


Name


    +------------+--------+--------+
    | PROFILE_ID |  TYPE  |  NAME  | 
    +------------+--------+--------+
    |      0     |   0    | Jo     |
    |      0     |   1    | Blog   |
    |      1     |   0    | Jim    |
    |      2     |   1    | Smith  |
    +------------+--------+--------+

    Type 0 = Given Name
    Type 1 = Family Name

Quert

This is the Query I am currently using.

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

Problem

This is the result I want and expect to get


    +------------+-------------+--------+
    | GIVEN_NAME | FAMILY_NAME | ADE    |
    +------------+-------------+--------+
    | Jo         | Blog        | 10     |
    | Jim        | NULL        | 20     |
    | NULL       | Smith       | 30     |
    | NULL       | NULL        | 40     |
    +------------+-------------+--------+

However this is what I actually get


    +------------+-------------+--------+
    | GIVEN_NAME | FAMILY_NAME | AGE    |
    +------------+-------------+--------+
    | Jo         | Blog        | 10     |
    +------------+-------------+--------+

From what I understand LEFT OUTER JOIN should return on the NULL value joins. What am I doing wrong? How do I change my Query to return the NULL value joun?

  • 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-28T13:05:10+00:00Added an answer on May 28, 2026 at 1:05 pm

    As soon as you have a WHERE clause on a table that is being LEFT JOINed on then you will immediately eliminate the NULL rows (i.e. where there is no match). So for starters, you should move the condition of given.type = 0 to the ON clause instead of in the WHERE clause. And I’m going to assume there is an issue with your other condition on the WHERE clause.

    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 AND given.type = 0 
    LEFT OUTER JOIN name family ON profile.id = family.profile_id AND family.type = 1
    LIMIT 0 , 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two relational tables: the Profiles table which contains 3 kinds of user
I have two tables, like these: Table People: VARCHAR Name INTEGER Age Table Message
I have two tables that I want to join into one table and use
I have two tables (in postgres) - ads and logs. After every insert into
I have a table with two decimal(18,0) fields. I am inserting into this table,
I have three tables, table one (tableA) containing users data like name and email,
I have two separate tables both with user id columns uid . I want
I have two tables, Profiles and ProfileInformation . Any profile may have multiple entries
Here's my situation. I have two tables: pledges and pledge_transactions. When a user makes
I have two tables that i am inserting records into. I am using PHP

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.