title: ORDER BY an equal value in MySQL
body: <p>All,
  I've got the following SQL query as of now:</p>
  
  <pre><code>SELECT * FROM $wpdb-&gt;posts
  JOIN $wpdb-&gt;term_relationships ON $wpdb-&gt;term_relationships.object_id=$wpdb-&gt;posts.ID
  JOIN $wpdb-&gt;postmeta ON $wpdb-&gt;postmeta.post_id=$wpdb-&gt;posts.ID
  WHERE 
  $wpdb-&gt;posts.post_status = 'publish' 
  AND $wpdb-&gt;posts.post_type = 'post'
  AND $wpdb-&gt;term_relationships.term_taxonomy_id='$vendor_category_to_use'
  AND $wpdb-&gt;postmeta.meta_key='zip'
  </code></pre>
  
  <p>I have a <code>postmeta.meta_key</code> called <code>featured</code>. Then the value of if the post is featured is in another column called <code>postmeta.meta_value</code>. If the <code>meta_value = "yes"</code> where the meta_key equals "featured" then I want to display this one first and then display the rest of the posts after that. How can I go about doing that?</p>
  
  <p>EDIT: Here is the data setup:</p>
  
  <pre><code>
  postid       meta_key      meta_value
  123          featured      yes
  324          featured      no
  182          featured      yes
  873          featured      yes
  </code></pre>
  
  <p>So in this example I'd like my posts to be displayed in this order:</p>
  
  <pre><code>
  postid       meta_key      meta_value
  123          featured      yes
  182          featured      yes
  873          featured      yes
  324          featured      no
  </code></pre>
  
  <p>I hope that helps!</p>
  
  <p>Here is the SQL that gets generated:</p>
  
  <pre><code>SELECT * 
  FROM wp_posts 
  JOIN wp_term_relationships ON wp_term_relationships.object_id=wp_posts.ID 
  JOIN wp_postmeta ON wp_postmeta.post_id=wp_posts.ID 
  WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post' AND wp_term_relationships.term_taxonomy_id='5' AND wp_postmeta.meta_key='zip' AND (wp_postmeta.meta_value = '46320' OR wp_postmeta.meta_value = '46321' OR wp_postmeta.meta_value = '46322' OR wp_postmeta.meta_value = '46323' OR wp_postmeta.meta_value = '46324' OR wp_postmeta.meta_value = '46327' OR wp_postmeta.meta_value = '46394' OR wp_postmeta.meta_value = '46402' OR wp_postmeta.meta_value = '46404' ) 
  ORDER BY (wp_postmeta.meta_key='featured' AND wp_postmeta.meta_value='yes') DESC, wp_posts.post_date DESC
  </code></pre>
  
  <p>Thanks!</p>