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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:19:56+00:00 2026-05-13T23:19:56+00:00

I am doing a couple of joins with a variable in the WHERE clause.

  • 0

I am doing a couple of joins with a variable in the WHERE clause. I’m not sure if I am doing everything as efficiently as I could, or even using the best practices but my issue is that half my tables have data for when tableC.type=500, and the other half don’t resulting in the entire query failing.

SELECT tableA.value1 , tableB.value2, tableC.value3 FROM tableA  
JOIN tableB ON  tableB.id=tableA.id
JOIN tableC ON  tableC.id=tableB.id
WHERE tableA.category=$var && tableC.type=500;

What I would like to happen is to still get tableA.value1 and tableB.value2 even if there is no field in tableC with a type=500.
any thoughts? i’m totally stumped as how to approach this…

  • 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-13T23:19:56+00:00Added an answer on May 13, 2026 at 11:19 pm
    SELECT tableA.value1 , tableB.value2, tableC.value3 FROM tableA  
    JOIN tableB ON  tableB.id=tableA.id
    LEFT JOIN tableC ON  tableC.id=tableB.id AND tableC.type=500
    WHERE tableA.category=$var;
    

    [INNER] JOIN (which you have) joins only if the values exist;

    LEFT JOIN returns NULL for tableC columns if no matching row in tableC is found.

    I think it’s necessary to move the tableC condition(s) into the ON clause when using a LEFT JOIN, as WHERE would filter out the NULL values (since tableC.type IS NULL != 500).

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

Sidebar

Related Questions

I'm doing project on object detection using javacv in that I went through couple
I have this query and it does a couple of joins, but I want
i have this stored procedure, doing a select query with couple of inner joins
I can figure out a couple of hack ways of doing this,...but no really
today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2
A couple of months ago I was doing Javascript programming on the Facebook platform,
I am currently doing some network programming and had a couple questions concerning timeouts.
I've seen a couple of ways of doing theism they both seem to work
I'm doing ray casting in the fragment shader. I can think of a couple
For this university project I'm doing (for which I've made a couple of posts

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.