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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:20:24+00:00 2026-06-13T11:20:24+00:00

I started out with a question in this thread: Need SQL guru for a

  • 0

I started out with a question in this thread:
Need SQL guru for a complex query

I now have that solved (thanks to SO), but now need to extract a bit more data.

Let’s say I have a query that joins 2 other tables, where criteria in each of the three tables can cause a row to be added to the result set. Something like:

    SELECT a.*
    FROM tableA a
    LEFT JOIN tableB b on a.b_id = b.id
    LEFT JOIN tableC c on a.c_id = c.id
    WHERE a.creator_id = 5 OR b.is_active = 1 OR c.can_attend = 1

Whatever the data is… basically what I need to do is determine, for each row in the result set, which criteria allowed it in. Was it because creator_id was 5, or because it was active, etc.

From this overly simplified example, you could say just look at the data, but notice the data for tables b and c are not being returned, and note that there are a variety of ways in which the join may add the row to the result set.

What I am looking for, I think, is a way to inject a value when a row is added to the result set, or something to that effect. Will make more sense if you look at the accepted answer in the linked question above.

Thanks for any input!

  • 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-13T11:20:25+00:00Added an answer on June 13, 2026 at 11:20 am

    You can do this using a case statement:

    SELECT a.*,
           (case when b.id is not null and c.id is not null then 'BOTH'
                 when b.id is not null and c.id is null then 'B'
                 when b.id is null and c.id is not null then 'C'
                 else 'A'
            end) as WhereFrom
    FROM tableA a
    LEFT JOIN tableB b on a.b_id = b.id
    LEFT JOIN tableC c on a.c_id = c.id
    WHERE a.creator_id = 5 OR b.is_active = 1 OR c.can_attend = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question most closely relates to the asp.net mvc3 framework. It started out as
I asked a non-related question in another thread scons dependency problems that was solved
I started to ask this question and then figured out the answer before submitting
I have a client/server question that i am trying to figure out the best
I'm hoping you guys can answer me a question? I've only just started out
I've started out with a div box that contains a header within it. My
I just started out with jQuery and really only need it for some very
We have just started out with Team Foundation Server 2008 / Visual Studio Team
I have just started out with testing some php mvc framework In it, it
I just started out with C and have very little knowledge about performance issues

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.