5

I am attempting to build a view with four filters (A, B, C, D). With Views 3 it is possible to select whether you want these filters to be chained with AND statements or OR statements. Is there a way to configure views so as to chain some of them with AND and others with OR?

For example, ending up with a query that is similar to:

SELECT * 
FROM {table} 
WHERE A = 0
  AND B = 0
  AND (C = 1 OR D = 1)`
5

Looks like this is entirely possible with the Views 3.x branch. You can create custom Filter groups directly in the Views UI itself, and set the AND/OR for each group separately.

  • 2
    This is possible in Views 2.x with the Views OR module, but it is much more confusing than the interface in Views 3.x. – tim.plunkett Mar 3 '11 at 4:15
  • The easiest way to do this in Views 2.x is probably with: api.lullabot.com/hook_views_query_alter – Alex Weber Mar 12 '11 at 3:23
  • Can Views 3.x nest? e.g. ((x OR y) OR (a AND b)) AND (i AND j) – alexkb Jul 11 '13 at 5:48
  • 1
    To answer, my question, you can do that, but you have to duplicate things, e.g. ((x OR y) AND (i AND j)) OR ((a AND b) AND (i AND j)). The other problem is, if some of these conditions are exposed, then you can't do it. Discussed here: drupal.org/node/1244772#comment-7430080 – alexkb Jul 11 '13 at 5:59
0

If you still wish to use views2 you can write your own filter as I did.

Though, in my case the only requirement was to place OR field IS NULL in the query.. so it worked for me.. i hope it could be extended further.. If someone likes the idea.. I could upload the code.. here..!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.