title: MySQL inner join only select 1 row
body: <p>I have a table (sampleTable) of website access dates as year-month-day, timestamps as year-month-day hour-minutes-seconds, user ids and website access ids. I want to select the access ids which correspond to the first access that occurred on the most recent day. So far I have attempted this with </p>
  
  <pre><code>select userID, MAX(dayAccessed) as latestDay from sampleTable group by userID;
  </code></pre>
  
  <p>which returns the most recent day. I then have used this in a inner join to rejoin this query with the original table which orders the columns correctly. My problem is that I cannot access the earliest access id on the most recent day for both user ids as</p>
  
  <pre><code>SELECT sampleTable.dayTimeAccessed, sampleTable.userID, latest.latestDay 
  FROM 
      (SELECT userID, MAX(dayTimeAccessed) AS latestDay 
      from sampleTable 
      group by userID) AS latest 
  INNER JOIN sampleTable 
  ON sampleTable.userID = latest.userID AND 
      sampleTable.dayTimeAccessed 
  limit 1;
  </code></pre>
  
  <p>only returns one field with the first userID matched. </p>