title: mysql - JOIN or UNION - not sure which, maybe both (part II)
body: <p><em>*</em> revised, but still not solved...*</p>
  
  <p>I want to combine data from two files but I am having trouble expressing the sort. I want to sort on either the CREATED date from the first file and the SHARED_DATE from the second file if it exists and it is larger.</p>
  
  <pre><code>file 1 : NODE 
  fields: CREATED, CHANGED
  
  file 2 : SHARE_CONTENT   
  fields:  SHARED_DATE ,  NODE (foreign key)
  </code></pre>
  
  <p>...</p>
  
  <pre><code>SELECT n.created, s.shared_date,
  
  (CASE WHEN s.shared_date &lt;&gt; NULL
     then  s.shared_date
     else n.created
  END) 
  as lastshare
  
  FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
  
  ORDER BY lastshare DESC
  </code></pre>
  
  <hr>
  
  <p>another possibility..</p>
  
  <pre><code>SELECT n.created, s.shared_date,
  FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
  ORDER BY MAX(n.created, s.shared_date) DESC
  </code></pre>
  
  <p>except mySQL does not seem to like MAX(a,b)     </p>