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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:24:23+00:00 2026-06-03T00:24:23+00:00

I’m trying to build a query that will pull events from a DB based

  • 0

I’m trying to build a query that will pull events from a DB based on a series of filters: baseId, title, age, and days it will occur.

Here’s what I’ve got so far:

SELECT * FROM [Events]
WHERE BaseId = 574 AND Title LIKE '%occurs%' AND MinAge <= 5 AND MaxAge >= 5 
AND (FreqType = 8 AND (FreqInterval & 2) = 2) 
OR (FreqType = 8 AND (FreqInterval & 4) = 4)

Without the OR line, it pulls just fine. With the OR line, it no longer cares about the BaseId, Title, MinAge, and MaxAge columns. Well, it does, but only up to the point where the OR is… and then it pulls all that match after the OR (regardless of the previous AND statements).

How can I get the query to filter by each column, and then also by each FreqInterval I want? I may have more than just 2, 4… could have any combination of 1,2,4,8,16,32, or 64.

Or, is there a way to do a AND (FreqType = 8 AND (FreqInterval & 6) = 6) using a SUM of the FreqInterval? I don’t fully understand bitwise querying.

  • 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-03T00:24:24+00:00Added an answer on June 3, 2026 at 12:24 am

    Add parenthesis:

    SELECT * FROM [Events]
    WHERE BaseId = 574 AND Title LIKE '%occurs%' AND MinAge <= 5 AND MaxAge >= 5 
    AND 
    (
       (FreqType = 8 AND (FreqInterval & 2) = 2) 
       OR (FreqType = 8 AND (FreqInterval & 4) = 4) 
    )
    

    OR has lower operator precedence than AND, you should put parenthesis around them. You can simplify it further:

       (FreqType = 8 
           AND ( (FreqInterval & 2) = 2 OR (FreqInterval & 4) = 4) )
       )
    

    And as your suggestion, it’s almost correct, here’s the right one though:

     (FreqType = 8 
           AND (FreqInterval & 6) <> 0 )
    

    By the way, another term for operator precedence is operator stickiness, if your original query is to be written explicitly, it is this:

    SELECT * FROM [Events]
    WHERE 
    ( 
      BaseId = 574 AND Title LIKE '%occurs%' AND MinAge <= 5 AND MaxAge >= 5 
      AND (FreqType = 8 AND (FreqInterval & 2) = 2) 
    )
    
    OR 
    
    (FreqType = 8 AND (FreqInterval & 4) = 4)
    

    That’s akin to 4 * 3 + 5, multiplication has higher precedence than addition, so 3 sticks to 4 instead of 5, so the output is 17. If your objective is to output 32, you should explicitly stick 3 to 5, put a parenthesis around 3 and 5, i.e. 4 * (3 + 5)

    So on your query that uses OR, to make them stick together, put parenthesis around them.

    Nonetheless, just like what you hinted, I like this better ツ

     (FreqType = 8 AND (FreqInterval & 6) <> 0 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.