title: custom MYSQL select query in WORDPRESS
body: <p>I'm creating a Wordpress site. I have a SQL table (wp_postmeta) with additional informations: dates and times for home and away mathes. (plugin ACF).
  Table row are like this:</p>
  
  <pre><code>meta_id   post_id  meta_key        meta_value
  1         123      home_0_date     20130512
  2         123      home_1_date     20130513
  3         123      home_0_time     13h
  4         123      home_1_time     16h
  5         123      away_0_date     20130514
  6         123      away_1_date     20130515
  7         123      away _0_time    18h
  8         123      away _1_time    19h
  </code></pre>
  
  <p>There is a corrispondence betweet home_n_date and home_n_time and between away_n_date and away_n_time.
  In fact in this case I'm adding two home matches: 12 / 05 / 2013 13h and  13 / 05 / 2013 16h
  and two away matches 14/ 05 / 2013 18h and 15/ 05 / 2013 19h .</p>
  
  <p>For a custom calendar I've this custom MYSQL query:</p>
  
  <pre><code>SELECT * 
  FROM wp_postmeta as pmd 
  JOIN wp_posts as ps ON ps.ID = pmd.post_id 
  WHERE (pmd.meta_key LIKE 'away_%_date' || pmd.meta_key LIKE 'home_%_date') 
  &amp;&amp; ps.post_status = 'publish';
  </code></pre>
  
  <p>This works fine but in this case I'm selecting only dates without time with no distinction between home and away matches.
  Now I want to add times and a way to differentiate home and away matches (adding some variables?)</p>
  
  <pre><code>"SELECT * 
  FROM wp_postmeta as pmd 
  JOIN wp_posts as ps ON ps.ID = pmd.post_id
  LEFT JOIN wp_postmeta as pmt  ON ps.ID = pmt.post_id 
  WHERE (pmd.meta_key LIKE 'away_%_date' || pmd.meta_key LIKE 'home_%_date') 
  &amp;&amp; (pmt.meta_key LIKE 'away_%_time' || pmt.meta_key LIKE 'home_%_time') 
  &amp;&amp;  (% = % /*???*/) 
  &amp;&amp; ps.post_status = 'publish';
  </code></pre>
  
  <p>Any idea?</p>