yohannan_sobin
yohannan_sobin

Reputation: 917

How to write sphinx queries with OR condition

I need to create a sphinx query in my project with OR condition. But giving an OR condition like

select cost FROM transactionsChart WHERE cost=25 OR cost=5;

is not working. It returns an error like

ERROR 1064 (42000): sphinxql: syntax error, unexpected OR, expecting $end near 'OR cost=5'

Can anybody help me....

Thanks in advance

Upvotes: 3

Views: 3593

Answers (2)

barryhunter
barryhunter

Reputation: 21091

Sphinx doesnt support OR in the WHERE clause, only AND.

For your specific example, could use IN syntax,

sphinxql> SELECT cost FROM transactionsChart WHERE cost IN (5,25);

or a more general solution is to use a virtual attribute

sphinxql> SELECT cost, IF(cost=25 OR cost=5,1,0) AS filter 
      FROM transactionsChart WHERE filter = 1;

Upvotes: 10

webo80
webo80

Reputation: 3393

Try with

select cost FROM transactionsChart WHERE cost=25 | cost=5;

Source - Official Documentation

Upvotes: -2

Related Questions