How to use use db_rewrite_sql() with db_query() in D7?
You have to use db_select() with the addTag() modifier.

The query you mention doesn't sound too crazy so it should be fine for db_select().
The only downside is it can be a bit slower.

As per the db_query() api docs:


  Use this function for SELECT queries if it is just a simple query string. If the caller or other modules need to change the query, use db_select() instead.