Thursday, 15 March 2012

mysql - Ordering SQL results by the field where they are found -



mysql - Ordering SQL results by the field where they are found -

we have search query allows users come in string , searches 3 separate fields via '%string%'. fields are:

name description type

when homecoming results , right order them arbitrarily. prefer results ordered first results found in name field, sec items found in description field, , lastly in type field. because have paging , sorting associated this, want returned in 1 record set. possible?

thanks in advance.

in mysql, next should work:

select * atable name '%string%' or description '%string%' or type '%string%' order case when name '%string%' 1 when description '%string%' 2 when type '%string%' 3 end ;

mysql sql

No comments:

Post a Comment