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

The Archive Base Latest Questions

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

I built a large script with several inner joins working as conditions (instead of

  • 0

I built a large script with several inner joins working as “conditions” (instead of using WHERE clauses). As a sample:

SELECT T1.*
FROM Table1 T1
    INNER JOIN Table2 T2
        ON T1.id = T2.id
    INNER JOIN Table3 T3
        ON T2.id = T3.id
    INNER JOIN Table4 T4
        ON T1.id = T4.id

etc…

Under certain conditions I need to skip one or several inner joins.
Till now, I had to duplicate the script commenting out the lines with the joins I don’t need.
Would it be any way to work with variables or IF clauses to skip a join, or at least a “select all” way?

  • 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-18T23:36:11+00:00Added an answer on June 18, 2026 at 11:36 pm

    Assuming php:

    $SQL = "
    SELECT T1.*
    FROM Table1 T1
        INNER JOIN Table2 T2
            ON T1.id = T2.id" . ($variable1 == x ? " OR TRUE=TRUE" : "") . "
        INNER JOIN Table3 T3
            ON T2.id = T3.id" . ($variable2 == y ? " OR TRUE=TRUE" : "") . "
        INNER JOIN Table4 T4
            ON T1.id = T4.id" . ($variable3 == z ? " OR TRUE=TRUE" : "")
    

    But I’m sure you should rather build the query dynamically:

    $SQL = "
    SELECT T1.*
    FROM Table1 T1";
    
    if ($variable1 == x) {
        $SQL .= " INNER JOIN Table2 T2 ON T1.id = T2.id";
    }
    
    if ($variable2 == y) {
        $SQL .= " INNER JOIN Table3 T3 ON T2.id = T3.id";
    }
    
    if ($variable3 == z) {
        $SQL .= " INNER JOIN Table4 T4 ON T3.id = T4.id";
    }
    

    etc. with all your joins.

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

Sidebar

Related Questions

I have a pretty large site and every page is built from several included
I'm working on a fairly large web site built in PHP that will potentially
I'm working on a Pig script (my first) that loads a large text file.
Were currently working on a script that reads the current users information from out
I'm working on a large c++ built library that has grown by a significant
I am working on a large website built over Croogo in CakePHP. Today, without
We recently built a large ASP.NET web forms application for a client and the
The company for which I work for has built a large ASP.NET MVC application
In a large Application is there any way to distinguish user-defined classes with built-in
The Settings/Accessibility Large Text setting sets the text size in some built-in Apps. How

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.