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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:51:25+00:00 2026-06-07T17:51:25+00:00

I’m building a complex search application with a large number of potential inputs. Each

  • 0

I’m building a complex search application with a large number of potential inputs. Each input is optional. I’m trying to build a query in a modular fashion.

Let’s say I have two distinct queries, each with independent WHERE conditions:

SELECT * FROM t1 WHERE t1.c1 = x

SELECT * FROM t2 WHERE t2.c1 = y

I’ve found the following code to be valid:

SELECT * FROM t1 INNER JOIN t2 ON t1.c2 = t2.c2 WHERE t1.c1= x AND t2.c1= y

However, since the WHERE conditions are grouped together at the end, it would be very difficult to implement this in a modular fashion. So, I tried this:

SELECT * FROM t1 WHERE t1.c1 = x INNER JOIN ON t1.c2 = t2.c2 WHERE t2.c1 = y

However, this code is invalid. What’s the best way to join an arbitrary number of tables with independent WHERE clauses?

  • 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-07T17:51:27+00:00Added an answer on June 7, 2026 at 5:51 pm

    The joins between the tables may be able to be implemented conditionally — and the where clauses concatenated at the end — like so:

    SELECT * 
    FROM t1 
      INNER JOIN t2 ON t1.c2 = t2.c2 
      INNER JOIN t3 ON t1.c3 = t3.c3  
      INNER JOIN t4 ON t1.c4 = t4.c4  
    WHERE t1.c1 = x 
      AND t2.c2 = y
      AND t3.c3 = z
      AND t4.c4 = a
    

    And you can build this as a string conditionally depending on which options the user chooses.

    While building the where clauses and the joins together dynamically may work, there may be some pitfalls to watch out for.

    First, the joins will still likely have to be custom built based on the the natural way the tables join together — for example, t3 may only be joinable to t2 and not t1. You’ll have similar issues with the where clauses. Each where clause will have to be custom built depending on the columns in the table.

    In other words, it’s unlikely that this problem is completely generalizable. In the end you’ll need to craft custom SQL that will depend on the specifics of the tables. Worse yet, over time the tables will change and the SQL will have to change with it. If you are building complicated SQL dynamically, you may be setting yourself up for a maintenance headache.

    Moreover, as your app grows you’ll likely want to tune the SQL for each combination to optimize the queries. Make sure you try to take this into account as you build this out.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.