What's up with my Query? (Part 2)
In last month's "What's up with my Query?" post, we explored the mysteries of seeing double and triple in our query results. This month, we will take another look at our query results, but this time we'll take a look at the impact that a simple little parenthesis can have on your query.
Let's say that you want to find anyone who is a Major Donor, who has also given a gift to Laurel's Vacation Fund, or to any fund last calendar year. Your query filters are:
-
Constituency Code equals Major Donor
-
AND Fund Description equals Laurel's Vacation Fund
-
OR Gift Date equals Last calendar yr
Essentially, these query filters include the proper criteria and operators that we need in order to find the records I mentioned above. However, if you run this query as is, you will receive anyone who is either coded as a Major Donor, has given a gift in the previous calendar year, or has at one time donated to Laurel's Vacation Fund. The results could meet any one piece of the criteria. This could multiply the amount of constituents you were looking for; thus resulting in several people in your query who couldn't dream of meeting your criteria. So how in the query world can we make this right?
PARENTHESES.
Yes, parentheses.
Located at the bottom right-hand corner of the Criteria tab of your query, these little buttons can be a big deal! Their purpose is to group together statements within a query - a great organization tool (I wish I had them for my closet!). To use them, simply highlight the row of criteria that you want to begin your group of statements, and then click on the open (or left) parenthesis. Then to close or end your group, highlight the last criteria statement for that group, and click on the close (or right) parenthesis. In this scenario (finding anyone who is a Major Donor, who has also given to Laurel's Vacation Fund, or to any fund at all last calendar year), we need to use parentheses for accurate results. Your query should look like this:
-
Constituency Code equals Major Donor
-
AND (Fund Description equals Laurel's Vacation Fund
-
OR Gift Date equals Last calendar yr)
As you can see, I've used the exact same filters that I previously mentioned, but I've grouped together my Fund Description and Gift Date criteria together with a set of parentheses. This way I find my Major Donors first, and out of that group, I find the ones that have given either to Laurel's Vacation Fund, or sometime last calendar year. Instead of my query pulling results that could meet each piece of criterion, it now finds only the specific results that I need.
For more tips, tricks, and info on the little buttons that are really a big deal (those parentheses), check out How to use parentheses in query from our Knowledgebase. Happy querying, and keep your eyes peeled next month for Part 3 of "What's up with my Query?".