You are trying to do the logic in the query but you should consider only collecting the variables from the query then creating the logic in the template using those variables
http://www.website.com/?q1=query_1&q2=query_2
{% set query_1 = request.query_dict.q1 %}
{% set query_2 = request.query_dict.q2 %}
{% if query_1 and query2 %}
{% for rows in database %} {% if query_1 is in row %} {% unless query_2 is in row %} {% endunless %} {% endif %} {% endfor %}
{% elif query_1 %}
{% %}
I didn’t take the time to look up the proper syntax for this but the jist is here and you can find the syntax in the HubL docs.