Im having issues with this mysql query, i need it to bring ONLY the files that have the condition WHERE st.class_id in ('%s') as principal, and the other conditions as secundary, tried changing the or’s to and’s with no luck,
thanks in advance.
$wpdb->get_results($wpdb->prepare("SELECT `st`.id,`st`.sub_name,`st`.stime,`st`.edate FROM {$_tables['subject']} AS st WHERE `st`.class_id in ('%s') and (`stime` BETWEEN '%s' AND '%s') OR (`edate` BETWEEN '%s' AND '%s');",[$start,$end,$start,$end, $value]));
>Solution :
Review operator precedence of AND versus OR.
You have a boolean expression in your WHERE clause like this:
WHERE A AND B OR C
Since AND has higher precedence than OR, it is evaluated as if you had done this:
WHERE (A AND B) OR C
That’s probably the source of your problem.
To override this, you need to use parentheses explicitly:
WHERE A AND (B OR C)