title: MySQL JOIN and Return the Longest URL per Domain
body: <p>I'm trying to create a joined SELECT statement that returns the longest URL for each domain. Can anyone help me grab the longest <code>link.page_href</code> for each domain?</p>
  
  <p>Heres my current SELECT statement.</p>
  
  <pre><code>SELECT link.page_href, domain.domain_name
  FROM `google_sort_backlink_domains` AS domain
  JOIN `google_sort_backlinks` AS link ON link.domain_id = domain.id
  WHERE domain.tablekey_id = 22
  </code></pre>
  
  <p>And heres a SQL Fiddle with the scheme and some test data: <a href="http://sqlfiddle.com/#!2/b9c7b/7" rel="nofollow">http://sqlfiddle.com/#!2/b9c7b/7</a></p>
  
  <p>Right now I get:</p>
  
  <pre><code>url, domain1
  url, domain1
  longest url, domain1
  url, domain2
  longest url, domain2
  </code></pre>
  
  <p>And what I want is</p>
  
  <pre><code>longest url, domain1
  longest url, domain2
  </code></pre>