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

  • Home
  • SEARCH
  • 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 834947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:44:58+00:00 2026-05-15T04:44:58+00:00

there is a question floated. It’s set in basic SQL terms, but its nature

  • 0

there is a question floated. It’s set in basic SQL terms, but its nature is pure math (so maybe I should visit https://mathoverflow.net too).

I have a table in some theoretical database with 6 fields, all are numbers. Also we have basic conditions, such as Field_1 > Field_5, Field_4 = 3 etc., 7 conditions total. I need to write a select, which satisfies at least 4 of them.

Writing long select with many logical conditions such as (cond_1 AND cond_2 AND cond_3 and cond_4) OR (…) is not a way, because 4-combination from 7 elements is equal to 140, and one doesn’t want to write so many conditions.

So how do I write a select in its simplified form?

  • 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-05-15T04:44:59+00:00Added an answer on May 15, 2026 at 4:44 am

    One way of doing it is to count 1 for each condition that the row satisfies and compare the sum to your target value:

    SELECT * 
    FROM yourtable
    WHERE (
              (CASE WHEN condition1 THEN 1 ELSE 0 END) +
              (CASE WHEN condition2 THEN 1 ELSE 0 END) +
              ...
              (CASE WHEN condition7 THEN 1 ELSE 0 END)
          ) >= 4
    

    Note that this will require evaluating all the conditions for each row so you won’t get a short-circuiting effect, but it’s simple and maybe it has good enough performance for you.

    If you’re using MySQL you can write this in a much simpler way because a boolean result is equivalent to 0 or 1 so you don’t need the CASE statements:

    WHERE (condition1) + (condition2) + ... + (condition7) >= 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been floated, but there are not any answers. In
This should be a basic css question, but as we all know sometimes it
There is a question here in stackoverflow with the same title but that is
There's another question: howto make diff look like svn diff? but I want the
This is my first question here but I'm sure there are many more to
I have a question: There are 3 divs. 2 of them should have their
I have a basic question,there are two incidents happended while working with Tomcat. 1.I
I know there are many variations of this question posted, but none I've found
I feel like this is a very basic CSS question: There seems to be
Newbie question: There are three types of Asp.Net controls : HTML server controls, Web

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.