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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:14:25+00:00 2026-05-12T07:14:25+00:00

i’m trying to build a join, but I can’t get it to work in

  • 0

i’m trying to build a join, but I can’t get it to work in MySQL, I know there must be a way.

I have two tables: 1. Setting and 2. User_Setting (and ofcourse User but that won’t be needed here).

Structure

Setting.setting_id
Setting.description
Setting.value_type
Setting.default_value

User_Setting.user_id
User_Setting.setting_id
User_Setting.value

I want to select ALL Setting records, and join User_Setting where there is a value. Classical outer join i would believe?

I have this query:

SELECT
`User_Setting`.`user_id`,
`User_Setting`.`value`,
`Setting`.`setting_id`,
`Setting`.`default_value`,
`Setting`.`value_type`,
FROM
`User_Setting`
Right Join `Setting` ON `User_Setting`.`setting_id` = `Setting`.`setting_id`
WHERE
`User_Setting`.`user_id` IS NULL OR
`User_Setting`.`user_id` =  1;

But this doesn’t work if a User with user_id 2 has a User_Setting record present for a certain setting_id, but the User with user_id 1 hasn’t got that setting_id record stored…

Does anybody have a query where ALL settings will be retrieved, with user_id and value NULL if the User_Setting record doesn’t exist?

  • 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-12T07:14:25+00:00Added an answer on May 12, 2026 at 7:14 am

    This (if you want to check that the user exists)

    SELECT  `User_Setting`.`user_id`,
            `User_Setting`.`value`,
            `Setting`.`setting_id`,
            `Setting`.`default_value`,
            `Setting`.`value_type`,
    FROM    user
    CROSS JOIN
            setting
    LEFT JOIN
            user_setting
    ON      user_setting.user_id = user_id
            AND user_setting.setting_id = setting.setting_id
    WHERE   user_id = 1
    

    or this (if you don’t want to check that the user exists):

    SELECT  `User_Setting`.`user_id`,
            `User_Setting`.`value`,
            `Setting`.`setting_id`,
            `Setting`.`default_value`,
            `Setting`.`value_type`,
    FROM    setting
    LEFT JOIN
            user_setting
    ON      user_setting.user_id = 1
            AND user_setting.setting_id = setting.setting_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.