This is my SQL Search statement.......
I want to return values on column NAME with first priority and then column Desc_Work.
Select * from posts
where Province = 'Western_Cape'
and NAME LIKE '%Etienne%'
or Desc_Work LIKE '%Etienne%'
What changes must I make to this to make sure that the rows in column NAME will be displayed first?
ORDER BY CASE
WHEN NAME LIKE '%Etienne%' THEN 1
ELSE 2
END
I also believe that you wanted where Province = 'Western_Cape'
and (NAME LIKE '%Etienne%'
or Desc_Work LIKE '%Etienne%')
UPDATE
Select * from posts
where Province = 'Western_Cape'
and (NAME LIKE '%Etienne%'
or Desc_Work LIKE '%Etienne%')
ORDER BY CASE
WHEN NAME LIKE '%Etienne%' THEN 1
ELSE 2
END
I assume you need (NAME LIKE '%Etienne%' or Desc_Work LIKE '%Etienne%')
in brackets - your original query returns records where (Province = 'Western_Cape' and NAME LIKE '%Etienne%' )
or Desc_Work LIKE '%Etienne%')
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With