I need to sort my results based on an integer field matching a value passed into my query. If the field matches the passed value, I want these rows sorted to the top. If the field does not match the value, I want these rows sorted after the rows that do match.
Something like this:
Order By IF id=$passedValue THEN 0 ELSE 1 END
If id is numeric you could do "order by fabs(id-$passedValue)". All records would be ordered by their numeric distance from the passed value which may or may not be useful.
Thanks, the id is numeric, but I need a true boolean because I have a secondary sort level that would be blown out unless I can truly have a boolean calculation on by first level.
Order By IF id=$passedValue THEN 0 ELSE 1 END, PostDate, Author
order by 1-bitisset(1,fabs(id-$passedValue)), PostDate, Author
You may consider using 2 sql's. The first to get the selected id(s) and the second to get the rest. Don't forget to exclude the selected id(s) in the 2nd sql.