All, I\'ve got the following SQL query as of now:
SELECT * FROM $wpdb->posts
JOIN $wpdb->term_relationships ON $wpdb->term_relationships.object_id=$
Also, you can use MySQL function named
FIELD(HAYSTACK, value[, ...values]).
This function returns index of haystack in values (FROM 1 to n, 0 - if not found).
Example
ORDER BY FIELD(wp_postmeta.meta_key, 'featured', wp_postmeta.meta_key),
FIELD(wp_postmeta.meta_value, 'yes', wp_postmeta.meta_value), wp_posts.post_date DESC
But, in your case, use the mathematical.coffee example. In my example you need to repeat the field name in the end of list, because if you don't - it will return 0 (zero) and elements than not in list will be first in result statement.