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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:02:29+00:00 2026-06-01T18:02:29+00:00

I am trying to write a where clause that will find people who have

  • 0

I am trying to write a where clause that will find people who have meet at least two of three criteria.
This is an example

   SELECT *
   FROM Personal
   WHERE
   [State] = 'Tx' or [City] = 'Austin' or [Gender] = 'Male'

So It should return anyone who Lives in Texas and Austin or Lives in Texas and is Male and so on, but not someone who just lives in Texas, they have to meet at least two of the criteria

My real query can have more criteria and also include a greater than two or exactly two and so on.

Thanks in advance

  • 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-01T18:02:30+00:00Added an answer on June 1, 2026 at 6:02 pm

    You might add matches in a series of case … then 1 else 0 end statements and compare final result to number of required matches:

       SELECT *
       FROM Personal
       WHERE
         case when [State] = 'Tx' then 1 else 0 end
         + case when [City] = 'Austin' then 1 else 0 end
         + case when [Gender] = 'Male' then 1 else 0 end
         >= 2
    

    Alternatively, you might break it into a list of union all:

    SELECT *
    FROM   personal
           INNER JOIN (SELECT id
                       FROM   (SELECT id
                               FROM   personal
                               WHERE  state = 'Tx'
                               UNION ALL
                               SELECT id
                               FROM   personal
                               WHERE  city = 'Austin'
                               UNION ALL
                               SELECT id
                               FROM   personal
                               WHERE  gender = 'Male') a
                       GROUP  BY id
                       HAVING COUNT (*) >= 2) a
             ON personal.id = a.id 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write app for service technicians that will display open service calls within
Trying to write a couple of functions that will encrypt or decrypt a file
I have a perplexing SQL select statement (ugly) that I'm trying to write in
I'm trying to write a function that will dump a recursive tree of window
I am trying to write a procedure that will fire the same select query
I am trying to write a function that will take an xml object, an
I am trying to write a generic repository that will perform basic methods on
Im trying to write a query that will pull the value of the selected
I'm trying to write a custom search that will search all categories and individual
I'm trying to write a custom filter for Dynamic data that will allow me

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.