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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:25:59+00:00 2026-06-01T22:25:59+00:00

The title sounds a bit odd, but what I am trying to do is

  • 0

The title sounds a bit odd, but what I am trying to do is as follows. Given the tables

A.a  A.b         B.a  B.c  B.d
---  ---         ---  ---  ---
1    X           1    10   Z
2    Y           1    30   W

I want a query that might look sort of like the following:

SELECT A.a, B.d FROM A
some kind of JOIN B ON A.a = B.a
...WHERE A.a = :a AND B.c = :c

Now, if I do the following replacements I want to get these answers:

:a  :c       A.a  B.d
--  --       ---  ---
1   10  -->  1    Z
1   20  -->  1    NULL
2   any -->  empty set

I’m using MySQL so FULL JOIN is out of the question.

NOT SOLVED

I thought I had worked it out myself:

SELECT A.a, CASE WHEN B.c = :c THEN B.d ELSE NULL FROM A 
LEFT JOIN B ON A.a = B.a
WHERE A.a = :a AND B.c = :c

But that gives:

:a  :c       A.a  B.d
--  --       ---  ---
1   20  -->  1    NULL
             1    10
  • 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-01T22:26:01+00:00Added an answer on June 1, 2026 at 10:26 pm

    Try this:

    select distinct a1.a, b2.d from A a1
    join B b1 on a1.a = b1.a
    left join B b2 on a1.a = b2.a and b2.c = 10
    where a1.a = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so the title might sound a bit confusing, but here's what I want
Sorry if the title sounds confusing - but this is what I am trying
I know that title sounds crazy but here is my situation. After a certain
(Title sounds a bit too fancy but I couldn't find a match so we'll
The title may sound a bit odd but I wanted to keep the title
I know the title sounds easy but I am looking for an example that
Title sounds a bit weird, but basically I'm wondering how I should go about
The title sounds a bit crazy but having the * function for java.lang.String in
Ok, the title might sound a bit vague but I really can't think of
Ok. So the title sounds confusing but that's probably the best way to describe

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.