0

I'm novice in MySQL. Please help me find out what I'm doing wrong. Using this Mysql: Order by like? question I tried to order my rows, but the result is same like without ordering. Here is a query example:

SELECT * FROM sc_products
WHERE name_ru = 'water' 
OR name_ru like 'water%' 
OR name_ru like '% water%' 
OR name_ru like '\"water%' 
OR brief_description_ru like '%water%' 
OR product_code like '%water%'  
OR product_code in (select product_code from ALLPRODUCTS where searchfilter like '%water%') 
OR product_code in (select product_code from SC_products prd JOIN SC_product_manufacturers mnf ON prd.manufacturerID=mnf.manufacturerID where mnf.filters like '%water%')
ORDER BY CASE
    WHEN (name_ru = 'water' AND 
            name_ru like 'water%' AND 
            name_ru like '% water%' AND 
            name_ru like '\"water%' AND 
            brief_description_ru like '%water%' AND 
            product_code like '%water%') 
    THEN 1
    ELSE 2 
END

I didn't find another place for my question. Sorry.

Community
  • 1
  • 1
Valery Statichny
  • 593
  • 7
  • 22

1 Answers1

0

You should use OR instead of AND inside CASE

VitaliyG
  • 1,837
  • 1
  • 11
  • 11