What is the difference between a Query and a Sub-Query?
For example, if you select the query below, you will locate all Individual and Organization records who have made at least one contribution before January 1, 2000.
Once the above line has been added to your query, you may enter a second condition. For example, the following line will locate all Individual and Organization records who have made a single contribution larger than $100 in value.
Adding both of these lines to your query as separate lines, or Query Joins, would yield the code below.
At first glance, one might intuit that this code will return all records with a contribution dated earlier than 1/1/2000 and also greater than $100.00. But looks can be deceiving.
In database-speak, the query code box above says "Return all contributions with a checkdate before 1/1/2000, and also return all contributions that are larger than $100."
In other words, we've told the database that we want to return two distinct groups of people:
This could be a significantly larger body of people than you were hoping to return! Ultimately, the goal is to find all of the records in the database who made contributions before 1/1/2000, AND whose value was greater than $100.
A sub-query is how the user can search for results that match more than one condition. A sub-query is entered as follows, using the Sub-Query Join drop-down menu.
You'll notice that the resulting code looks slightly different from the code created by our original example.
This will return all records who meet both conditions.