Drupal How to alter Views Query (SQL)
If you are a Drupal Developer using the Views module, is probable you want the option to rewrite the SQL query executed for this module.
Maybe because you think it's easier this way or maybe because you can't do complex stuff like grouping elements, or an argument taxonomy negation or something similar.
No matter the reason why you need to change the query, now you can do this using the module Views modify query.
The problem with this module is that the developers don't provide any sample about how to use it, but here you can find a short description.
1. This module exposes the view object, enabling the option to modify the object of class views_query defined in modules/views/includes/query.inc
2. If you want to check the object values then you can do this:
3. If you want to add a custom "where condition" using other php elements, check the sample below:
$request_uri = explode("/",urldecode($_SERVER['REQUEST_URI'])); $term = strtolower(str_replace('-',' ',$request_uri)); $this->query->add_where(0,"lower(term_data.name) != $term");
The code above adds an extra "where condition" using values from URL.