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 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

Ask A Question

Stats

  • Questions 451k
  • Answers 451k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To load an image as a class resource, the following… May 15, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer Just access files using the normal IO routines using UNC… May 15, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer Why reinvent the wheel ? The Apache Http Client 4… May 15, 2026 at 8:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.