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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:19:25+00:00 2026-06-16T07:19:25+00:00

I am working on expanding user profiles for my project, adding more info. I

  • 0

I am working on expanding user profiles for my project, adding more info. I was just adding countries, when I hit a problem. This is my query for selecting all profile data needed:

SELECT c.*, d.username, d.email, e.country_name
    FROM user_profiles c, users d, country e
    WHERE c.user_id = ".$id." AND d.id = ".$id."
    AND e.country_name = (SELECT country_name FROM country WHERE id = c.country_id)

c.* should select all columns from user_profiles.

The $id is an id of user selecting wich profile should be returned. The problem is, keeping registration as simple as possible, I dont have a country selector there. So when this query comes in action, column country_id from user_profiles is empty, that means when I want to return the country_name, the query result is empty, so no profile data is returned.

I have tried to rewrite this with CASE or LEFT JOIN, but I think I am missing something. I want to find if country_id is not null, when it is not, select also country_name with this country_id. Any ideas?

Thank you kindly for responds.

  • 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-06-16T07:19:27+00:00Added an answer on June 16, 2026 at 7:19 am

    You can use a LEFT JOIN, but it would be so much easier to do that if you started off by using the cleaner and more modern JOIN syntax:

    SELECT c.*, d.username, d.email, e.country_name
    FROM user_profiles c 
    JOIN users d ON d.id = c.id 
    JOIN country e ON e.country_id = c.country_id
    WHERE c.user_id = 42
    

    Now to solve your problem you can just add LEFT:

    LEFT JOIN country e ON e.country_id = c.country_id
    

    Full query:

    SELECT c.*, d.username, d.email, e.country_name
    FROM user_profiles c 
    JOIN users d ON d.id = c.id 
    LEFT JOIN country e ON e.country_id = c.country_id
    WHERE c.user_id = 42
    

    Related

    • Why isn't SQL ANSI-92 standard better adopted over ANSI-89?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, this web application I'm working in haves three vertical columns expanding for the
Still working on a web application as a school project, and it just seems
i've been working on this for more than hours and hours and i cant
I've been working on expanding my vim-foo lately and I've run across a couple
Working with H2 I get this error when I try to write a row
Working on the problems on Project Euler to try to learn Clojure. I'm on
I'm working on a website where the user should be able to fill out
I'm working on a ruby project using Sinatra as a framework and have a
Hey there, Now im working this base on dmitko tutorial on extending django-registration post
A mobile application that I'm working on is expanding in scope. The client would

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.