You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND v.string <= 86399) OR ( v2.string >= AND v2.string <= 86399) OR (v.strin...' at line 1 QUERY: SELECT count(distinct e.guid) as total from katanam_entities e JOIN katanam_metadata m on e.guid = m.entity_guid JOIN katanam_metadata m2 on e.guid = m2.entity_guid JOIN katanam_metastrings v on v.id = m.value_id JOIN katanam_metastrings v2 on v2.id = m2.value_id where e.type='object' and e.subtype=11 and m.name_id='195' and m2.name_id='197' and ((v.string >= AND v.string <= 86399) OR ( v2.string >= AND v2.string <= 86399) OR (v.string <= AND v2.string >= ) OR ( v2.string <= 86399 AND v2.string >= 86399)) and e.site_guid = 1 and e.container_guid = 1876 and ( (e.access_id IN (2)
OR (e.owner_guid = -1)
OR (
e.access_id = 0
AND e.owner_guid = -1
)
) and e.enabled='yes') and ( (m.access_id IN (2)
OR (m.owner_guid = -1)
OR (
m.access_id = 0
AND m.owner_guid = -1
)
) and m.enabled='yes') and ( (m2.access_id IN (2)
OR (m2.owner_guid = -1)
OR (
m2.access_id = 0
AND m2.owner_guid = -1
)
) and m2.enabled='yes')