Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order By: Returning unLIKE before LIKE?

Tags:

sql

sqlite

This should be an easy one, but I am having a moment. Why does ORDER BY with LIKE sort the matching results as a higher value than the non-matching? To get the results I expect I have to mix ASC and DESC on what is otherwise the same data:

create table foo (name text);
select name from foo order by name like 'm%' desc, name;
like image 762
Sam Avatar asked Apr 16 '12 17:04

Sam


1 Answers

"x" like 'm%' is FALSE; "motorcade" like 'm%' is TRUE; "FALSE" < "TRUE".

like image 65
Carl Manaster Avatar answered Oct 16 '22 06:10

Carl Manaster