Ben Clayton Ben Clayton - 1 year ago 227
SQL Question

Where clause has OR In Sphinx

Is there a way to do this line in sphinx search

where field_a = 'Value' or field_b = 'Value'

I have tried so far

$sphinx->where(field_A | field_B, '=', 'Value')

But it's not working.
Could someone help me to get over this?

Answer Source

Sphinx itself does not support 'OR' in the WHERE clause.

But can do something like

SELECT id, (attribute_a = 'Value' OR attribute_b = 'Value') AS test
FROM index
WHERE test = 1

It's a little convoluted, but does work. Also no idea what library you using to build the query, so left as an exercise to how to construct a SQL query like above.

(Also note I changed to call the column, attributes instead. Sphinx treats attributes and fields very differently. Clarifying this is a way of filtering attributes)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download