var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: ORDERing by WHERE condition
Lets say the result has 10 rows, 4 from `Name` = 'John' and 6 from `Name` LIKE '%John%'.
SELECT * FROM `tbl` WHERE `Name` = 'John' OR `Name` LIKE '%John%'
I want the order such that the first 4 rows are from `Name` = 'John' and the last 6 rows are from `Name` LIKE '%John%'.
Is that possible ?
WHERE Name LIKE '%John%'
BY CASE WHEN Name='John'
ELSE 937 END
1. Couldnt get the THEN 42 ELSE 937 part. Are you referring to a STORED PROCEDURE ?
2. Is it possible if the query was
SELECT * FROM `tbl` WHERE `Name` = 'John' OR `Name` LIKE '%Smith%'
1. no, i'm not
2. yes, it is
please, why don't you do me a very small favour, and actually try my query
This is excellent r937 - I did this and worked like a charm !
I think I got how this is sorting the result-set based on the CASE value matching against the WHERE clause, but is there some detailed explanation to this ?
SELECT * FROM `tbl` WHERE
`Name` LIKE '%an%'
WHEN `Name` LIKE 'an%' THEN 1
WHEN `Name` LIKE '%an' THEN 1000
Docs doesnt have a sorting-by-where-clause example.
it looks like you understand how CASE works