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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:58:20+00:00 2026-06-03T13:58:20+00:00

I have the following table, TableA, with some data ColA ColB 0 5 0

  • 0

I have the following table, TableA, with some data

ColA  ColB
0      5
0      6

I have another table, TableB, with some data

ColC  ColD   ColE
5      10     5
5      15     10
6      20     10

ColC is the foreign key for ColB. For each row in TableA I need to return ColA, ColB and ColD. The row to select in TableB depends on the value of ColE that is set through a parameter.

For example: If my parameter is set to 5, I should get two rows back as follows:

ColA  ColB  ColD
0      5     10
0      6     null

However, if my parameter is anything other than 5 and no row exists in TableB, it uses a parameter value of 5 instead and retrieves the value from ColB (if a row exists).

I tried several things but can’t seem to come up with the solution. Thank you for your help!

  • 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-03T13:58:21+00:00Added an answer on June 3, 2026 at 1:58 pm

    Try this:

    select ColA, ColB, ColD
      from TableA a
      left outer join TableB b on (a.ColB = b.ColC and b.ColE = 5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table, TableA, with data: ID ColA 0 10 1 null
I have some data in a table that looks roughly like the following: table
I have the following tables: create table TableA ( Id int primary key identity,
Lets say I have a table with some data like the following: ID text
I have following table and data: create table Foo ( id int not null,
Lets say we have the following: create view view_1 as ( select key, data
I have a following table: bid | data 1 | a 1 | b
I want to fetch some data from the following database table 'article'. i want
I have a table with some persistent data in it. Now when I query
I have two tables that are indirectly related by another table TableA - ID,

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.