0

I would like to show a query result displaying titles which contain Summer festival and Summer festivals ordered first in the list of records.

This very basic SQL query gives following result:

SELECT title FROM items


title
-----------------
Just a test
Just another test
New test
Testing
Summer festival
Summer festivals

My goal is to display the result as following:

title
-----------------
Summer festival
Summer festivals
Just a test
Just another test
New test
Testing
Harvey
  • 1,320
  • 3
  • 13
  • 33
Daniel
  • 3
  • 1

2 Answers2

0

Try conditional order by

SELECT title 
FROM items
ORDER BY CASE WHEN title LIKE '%Summer festival%' THEN 1 ELSE 2 END, title
Serg
  • 22,285
  • 5
  • 21
  • 48
0

To order by a specific string you could use something like this

SELECT title FROM items ORDER BY (CASE WHEN title = 'Summer festival' THEN 1 WHEN title = 'Summer Festivals' THEN 2 ELSE 3 END)

That should give you your output you require by ordering by two specific strings first then displaying the rest of the results after.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Harvey
  • 1,320
  • 3
  • 13
  • 33