Merging Queries vs Complex Queries Best practices?

Options
Hi folks,

I've always leaned toward doing queries that use and, or, brackets etc to get a list, rather than a number of queries and merging them together. Obvioulsy, once a query gets too complex, it's better to merge, but I see a lot of people prefering to do five queries each with one criteria, then merging them, rather than a query with several criteria.


Such as Constituents with Gifts of $1000+ or (Constituents with greater than $100 AND Constituents with at least five gifts)

VS Doing the first one, and then merging with the items in the brackets. (Pardon the rough example.)


I'd love to hear where you "draw the line" between building within one query, and merging.


Ali

Comments

  • I also try and use and/or statements as much as possible to avoid merging queries - we have over 400 queries in more than 30 folders, so I'm not in any rush to clutter that up further! laugh


    With your example below, I would do that in a single query. I will begrudgingly merge queries for things that I physically can't accomplish with a single query, for example "constituent has Constituent Code A and also has Constituent Code B".


    Creating lots of separate queries seems like it would be a bit of a pain to keep everything tidy. Either you would end up creating duplicates of queries with very simple criteria, or you would re-use the same query for several merges but then not all the sub-queries for a particular merge can sit together in the folder. Would be interested to hear if anyone's got any tips to make this more workable though.

     
  • Alan French:

    I also try and use and/or statements as much as possible to avoid merging queries - we have over 400 queries in more than 30 folders, so I'm not in any rush to clutter that up further! laugh


    With your example below, I would do that in a single query. I will begrudgingly merge queries for things that I physically can't accomplish with a single query, for example "constituent has Constituent Code A and also has Constituent Code B".


    Creating lots of separate queries seems like it would be a bit of a pain to keep everything tidy. Either you would end up creating duplicates of queries with very simple criteria, or you would re-use the same query for several merges but then not all the sub-queries for a particular merge can sit together in the folder. Would be interested to hear if anyone's got any tips to make this more workable though.

     

    Yes... that sums up my thinking nicely. I will say though, I do keep a standard "kill file" as a separate query, that I run all my mailings against by merge as a last step to make sure I pull all the tricky "do not mails" etc.

  • We've discovered that merging queries sometimes causes the incorrect dropping of records from the results, so we try to use a single query whenever possible.


    But, there are those cases though where you have to merge because of funcionality limitations (such as excluding based on a relationship) or just too convoluted to do in a single query.  So we merge, and hope for the best.


    Shani
  • I often (particularly when pulling a mailing list) will use simple Queries and an Attribute.


    I create an Attribute, usually prefixed with a number to put it at the top of the Attribute Tab, and then use Global Add and start with the top of the heirarchy.  If we want all current Board members on the list, I'll pull up my Query for that and do a Global Add (using the Attribute's Description & Comment Fields for additional information).  Then we want to include all recent donors, but because it's an appeal, we want to know when the most recent gift was, so I'll write a Query for donors from FY15 and add the Attribute, then FY14 and add the Attribute, etc. (set the Attribute to Allow Only One Per Record and the Global Add will only add it to those not already "on the list").  Once I've added everyone, then I can go thru and start either removing (Global Change provides a method of globally deleting Attributes from Records in a Query) or changing the Description/Comment to DNM (do not mail).  (I prefer to end up with Appeal Tags on all records that qualified, and use a Package of "Do Not Mail" for those that were pulled from the list...that way when someone asks why so-and-so was/wasn't on the list, I know either way.)


    In the end, I can write a Query for all Constituents with this Attribute, and it provides a nice little list that really operates like a Query List (I was using this method before Query Lists were an option...and as I said, once a record is added to the list, I don't like to remove them altogether).  Then I can easily Globally Add an Appeal Tag, or Actions, or whatever, and when done with the Attribute, use Global Change to remove the Tags from all Records and have that Attribute ready to use for the next list.


    For Queries that are more dynamic and need to be available over time, I generally prefer more complex over merged...  I really wish that RE would allow you to copy the Criteria (particularly of a Summary Field), though.  That would speed things up considerably.


    If you use complex queries (or even merged), I suggest that you regularly test and spot check as you build the Query.  Nothing worse than getting to the end of some project and realizing that a number of records were missed because of one incorrect line of Criteria or qualifier (AND, OR, or parentheses).
  • This is a really interesting way to look at it - we do quite a few mailings and invariably there is the person that is just not on there and I can't quite figure out why they were missed. I wonder if some of those are dropped out from merging. Hmmmm.
  • I also prefer to create a single query whenever possible because after you merge the results are static.  This is fine for some things, but most of the time I prefer dynamic results.  I also don't like the limitations for creating the query criteria - no parenthesis within parenthesis for example.
  • Nicole S:

    I also don't like the limitations for creating the query criteria - no parenthesis within parenthesis for example.

    A little trick I have occasionally used to get around this limitation is to add an extra criteria that will be satisfied by every record, which will make no difference to the query results but gives me an extra criteria line that I can put the second bracket on.


    As an example, instead of having:

     


    [a whole bunch of other criteria]

    AND Constituent Code equals Alumni))




    which wouldn't be possible as you are limited to one closing parenthesis per line, you could do:

     


    [a whole bunch of other criteria]

    AND Constituent Code equals Alumni)

    AND Constituent ID not blank)

  • As a general rule, if I have a query that has multiple AND and OR statements or where you're really requiring the use of 'nested' conditions (which query can't handle) then I start to think about merging queries.  


    Also, on the issue of merging 'dropping out records' then there's some issue with either the data on the record or how you've structured your queries you're using as components or the merge operator you're using.  
    • Almost always I find it's some data on the record that's causing it to drop out. One culprit is having 'Send Mail' unchecked or the Date To populated in the address - so the query may automatically drop those out ... 
    • The merge is just doing what you're telling it to do, so it's usually not the culprit unless I did something wrong in the structuring of the queries being used.
    What I haven't seen stated here as a 'plus' for merge queries is if you have a complex query it's often difficult for someone else to decipher. If you set it up as a merge query and name the queries part 1, part 2, takeout, etc. then it's often easier for someone coming in cold to actually figure out what you've done.  BUT if they then want to reuse the work, they have to understand about refreshing static queries.  
  • I'm afraid I'm on the other side of this discussion.  I'm all for a query doing just one thing.  If people are missing from a mailing, it's usually because I made the query too complicated.  I, too, hate the "Static" Query List, but it isn't all that static, really.  I have my add and subtract queries, and can "clean" a list with those or individually.  As an example, we wanted to send an appeal to all people who had given anything in the last 5 years, had given over $500 in one gift between 6 and 10 years back, or had been added in the last 3 but hadn't given anything.  That's two or three very simple queries that can be merged (and automatically de-duped if necessary) in Query List.  I then decide to  add all Alumni with valid addresses - another simple (and "Master") query. But I want to pull out all the Do Not Solicits, and I don't want to send it to the Board members or the President's Circle donors.  I have canned queries to pull all those individual lists, so I subtract them one after the other.  If I tried to put all that in one query, I'd get all kinds of people who I didn't want but who fulfilled one or more of the "higher" criteria.  The other advantage for me is that by doing the merge (all the adds and then the subtracts) I can get pretty good numbers to tell the printers.  I usually do that early in the process, then go back and do it more carefully again later.  Then the list is plugged into our "appeal review" export (with gift data and addresses and salutations, etc.) and we massage that in Excel before using it to print and mail.


    My brain definitely works more like the complicated multi-criteria query, but I've found it's safer and more accurate to just merge simple ones.  My two cents worth (all that typing is only worth two cents???).wink
  • I mostly use merged queries when the query is already complicated and excludes records (i.e. not equal to, not one of).  It's easier to think about (and explain to the person that requested help on how to make the query) when you have one query that has the records you want, and then a separate query that 'includes' the records you don't want.  Then merge using SUB.


    The other time is when querying on Prospect tab Ratings, thanks to the lack of a Prospect query type and having to use a Constituent query type.
  • Gracie brought up some points that also highlight a benefit of the more 'modular' approach - you can have all the commonly used basic queries as standard in your system, and then using merging you can mix them fairly easily when needed.  If you've already got those common queries built, it's actually faster to just pull them out and use as elements in a merged query vs. building a brand new query with all the pieces.

     
  • I'm not so sure about the reason for the dropped records in merging.  We've had records in Query A and in Query B and when we merge A AND B, some will disappear.  No logical reason, but there it is.


     
  • Shani -


    The AND operator finds records that exist in both queries.. The OR operator will put both queries together.

    Is that perhaps a possible reason for the issue?
  • Nope - they WERE in both queries, so the AND operator should have worked.


    It's not large scale dropping, just one or two out of many.  But annoying just the same.


     
  • JoAnn Strommen
    JoAnn Strommen ✭✭✭✭✭
    Ancient Membership Facilitator 4 Name Dropper Photogenic
    From experience - what looked to be the same record in Query A and Query B was really not.  Query A pulled Smith, Bob & Jane - pulling Bob's record.  Query B pulled Smith, Jane & Bob - pulling Jane's record.  Merged queries - neither record pulls. blush


    Just a possible reason.


  • I will echo the voices of those who prefer to use a single query except when that is just not possible. In my opinion (and an opinion is all it really is), that's the only real use for merged queries to begin with: To get to those hard-to-reach reporting spaces that a single query can't swing.


    This can also depend a lot on how the operator in question thinks, though. I've worked with some people who just never got a good grasp of query logic, and would throw up their hands at anything with more than two criteria. I've also worked with people who had no problem with query logic, but who never could get the merge types straight. I myself still have to look them up every time I resort to using them and I am still surprised every time because there are two of them I constantly confuse for one another. I look up which is which and go "Huh...not how I remember that..."





     
  • JoAnn Strommen
    JoAnn Strommen ✭✭✭✭✭
    Ancient Membership Facilitator 4 Name Dropper Photogenic
    Shani,

    If you know what records, I'd look at the constituent ID or Import ID to verify they are the same.  If the same, I'd have a long talk with support about glitch with the merge process.


    It may be happening to others but not caught.  If there's a glitch, to me that's an issue BB needs to address.
  • Nicole S:

    I also prefer to create a single query whenever possible because after you merge the results are static.  This is fine for some things, but most of the time I prefer dynamic results.  I also don't like the limitations for creating the query criteria - no parenthesis within parenthesis for example.

    Something I learned somewhere along the way...


    If you have a merge query and you want an updated set of results:

    Rerun the sub queries (the ones you're merging), run the static merge query you had already set up, and then on the result page click on "results" and then "refresh".  This will re-preform the merge but using the results from the new versions of the sub queries.


    So, let's say you have Query "Number 1" and Query "Number 2" that on January 1st you merged into query "Number 3".  Now it is January 8th and you want a new version of that merged  query.  Rerun Number 1 and Number 2.  Open Number 3 and run it.  You will see the January 1st results.  Then, from the menu above the results, click on records...refresh.  You will now see the results as of January 8th (when you reran the base queries and asked for refreshed results in the merged query).


    I hope that made sense!


    Shani
  • Thank you! These are some great points to think about. I like that there isn't a clear "rule" on this, that tells me that either method will work, it's a matter of which one the user feels most comfortable with and gives the best results.


    I think my next mailing, I'm going to try doing it both ways and comparing my results, just to see what sort of difference in results I get. 

Categories