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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:36:10+00:00 2026-06-11T06:36:10+00:00

I want to Join multiple tables using IF ELSE statement within Sql Query when

  • 0

I want to Join multiple tables using IF ELSE statement within Sql Query when column value match with the specified text.

Suppose I have checked coloumnName='Value' Then I want to JOIN an additional Table; otherwise, I do not want to join it. Is this possible? How can I do that?

  • 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-11T06:36:11+00:00Added an answer on June 11, 2026 at 6:36 am

    You cannot conditionally join a table You need to join all tables unconditionally using an outer join, use the condition in the join criteria, and pick the values that you want from the returned data set, like this:

    select r.id, p.name, a.name, t.name
    from requests r
    left outer join person p on r.type='person' and r.item_id = p.id
    left outer join animal a on r.type='animal' and r.item_id = a.id
    left outer join thing t on r.type='thing' and r.item_id = t.id
    

    The example above shows “requests” that have an item_id that references a person, an animal, or a thing. The type column decides which table is referenced.

    The result will have three columns for name, at most one of which will be non-null.

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

Sidebar

Related Questions

I want to join two tables using JPQL : SELECT * FROM A LEFT
I have two tables which I want to join together using a left outer
I'm trying to join multiple myqsl tables and then process resulting arrays using PHP
I want to be able to use multiple keys to join two tables. Is
I am trying to JOIN multiple tables to the same value in a table.
I have multiple tables that I want to join to get a specific result.
I want to join two tables with several hundred columns, like this: select *
I want to join two tables (below) which i get. But then I want
I have 4 tables and i want to join them and extarct 4 values.
I have two tables that I want to join together. Table1 Year, ID, Theme,

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.