Search code examples
mysqlsqlconditional-statementswhere-clausehaving

WHERE "OR" HAVING Conditions instead of "AND"


i want to run sql query (mysql) and i have multiple condition in WHERE & also multiple condition in HAVING,
SQL apply "AND" between WHERE & HAVING, i want to apply "OR" between.

WHERE Condition 1, Condition 2 .... Condition N
{{OR}}
HAVING Condition 1, Condition 2 .... Condition N


Solution

  • The only option that I can see to solve your problem is to separate the query and apply UNION DISTINCT to remove the duplicated results. The solution could be something like:

    SELECT * FROM t1 WHERE ...
    
    UNION DISTINCT
    
    SELECT * FROM t1 HAVING ...