title: Complex MySQL not returning the results I need
body: <p>tl:dr
  I am needing to take the most recent row per employee from one table and match it to multiple rows per employee from another table.  I am able to get the most recent entry per employee from the one table, but cannot pull the data from the second table.</p>
  
  <p>Details:</p>
  
  <p>The first two tables show some representative data from my database.  The data and tables shown here are snippets of my full schema and data set.
  (TABLES: 'employees' and 'employee_payrollhours')</p>
  
  <p>employee_number:    this is an ID number to ID  the individual employee
  inserted_at:        This is a date/time stamp when the record was saved to the database
  datetime_in:        This is the date/time when the employee started his shift</p>
  
  <pre><code>SELECT employee_number, last_name, inserted_at FROM employees;
  TABLE:  employees
  +-----------------+-------------+---------------------+
  | employee_number |  last_name  | inserted_at         |
  +-----------------+-------------+---------------------+
  |       123456789 | Lastone     | 2018-02-26 22:26:38 |
  |       123456789 | Lastone     | 2018-03-15 15:16:14 |
  |       123456789 | Lastone     | 2018-03-15 20:57:23 |
  |       123456789 | Lastone     | 2018-04-16 00:10:27 |
  |       223456789 | Lasttwo     | 2018-04-16 03:37:49 |
  |       270000001 | Lastthree   | 2018-04-06 22:42:50 |
  |       270000001 | Lastthree   | 2018-04-17 14:10:01 |
  +-----------------+-------------+---------------------+
  
  
  SELECT employee_number, datetime_in FROM employee_payrollhours
  TABLE:  employee_payrollhours
  +-----------------+---------------------+
  | employee_number | datetime_in         |
  +-----------------+---------------------+
  |       123456789 | 2018-04-06 08:00:00 |
  |       123456789 | 2018-04-08 08:00:00 |
  |       123456789 | 2018-04-10 08:00:00 |
  |       123456789 | 2018-04-15 08:00:00 |
  |       123456789 | 2018-04-17 08:00:00 |
  |       123456789 | 2018-04-19 08:00:00 |
  |       223456789 | 2018-04-06 08:00:00 |
  |       223456789 | 2018-04-08 08:00:00 |
  |       223456789 | 2018-04-10 08:00:00 |
  |       223456789 | 2018-04-15 08:00:00 |
  |       223456789 | 2018-04-17 08:00:00 |
  |       223456789 | 2018-04-19 08:00:00 |
  |       270000001 | 2018-04-07 08:00:00 |
  |       270000001 | 2018-04-09 08:00:00 |
  |       270000001 | 2018-04-11 08:00:00 |
  |       270000001 | 2018-04-16 08:00:00 |
  +-----------------+---------------------+
  </code></pre>
  
  <p>To get one row for each employee from the employees</p>
  
  <pre><code>SELECT * FROM employees GROUP BY last_name
  </code></pre>
  
  <p>and to get the most recent entry for each employee from the employees table.</p>
  
  <pre><code>SELECT * FROM employees e1
  WHERE Inserted_at = 
      (SELECT MAX(e2.Inserted_at)
      FROM employees e2
      WHERE e1.Employee_Number = e2.Employee_Number)
  +-----------------+-------------+---------------------+
  | employee_number |  last_name  | inserted_at         |
  +-----------------+-------------+---------------------+
  |       123456789 | Lastone     | 2018-04-16 00:10:27 |
  |       223456789 | Lasttwo     | 2018-04-16 03:37:49 |
  |       270000001 | Lastthree   | 2018-04-17 14:10:01 |
  +-----------------+-------------+---------------------+
  </code></pre>
  
  <p>This is what I want.  I want the most recent entry for each employee from 'employees' displayed with the corresponding employee data from the 'employee_payrollhours' table.</p>
  
  <pre><code>+-------------------+---------------------+
  |     last_name     | datetime_in         |
  +-------------------+---------------------+
  |       Lastone     | 2018-04-06 08:00:00 |
  |       Lastone     | 2018-04-08 08:00:00 |
  |       Lastone     | 2018-04-10 08:00:00 |
  |       Lastone     | 2018-04-15 08:00:00 |
  |       Lastone     | 2018-04-17 08:00:00 |
  |       Lastone     | 2018-04-19 08:00:00 |
  |       Lasttwo     | 2018-04-06 08:00:00 |
  |       Lasttwo     | 2018-04-08 08:00:00 |
  |       Lasttwo     | 2018-04-10 08:00:00 |
  |       Lasttwo     | 2018-04-15 08:00:00 |
  |       Lasttwo     | 2018-04-17 08:00:00 |
  |       Lasttwo     | 2018-04-19 08:00:00 |
  |       Lastthree   | 2018-04-07 08:00:00 |
  |       Lastthree   | 2018-04-09 08:00:00 |
  |       Lastthree   | 2018-04-11 08:00:00 |
  |       Lastthree   | 2018-04-16 08:00:00 |
  +-------------------+---------------------+
  </code></pre>
  
  <p>This query gives me the error "Subquery returns more than 1 row"</p>
  
  <pre><code>SELECT employees.*, employee_payrollhours.*
  FROM employees, employee_payrollhours
  WHERE employee_payrollhours.employee_number = (select employee_number from employees group by last_name);
  </code></pre>
  
  <p>This query gives me mixed up data.</p>
  
  <pre><code>SELECT employees.last_name, employees.employee_number, employee_payrollhours.employee_number, employee_payrollhours.datetime_in
  FROM employees, employee_payrollhours
  WHERE employee_payrollhours.employee_number = employees.employee_number;
  </code></pre>
  
  <p>and this query gives me zero returned results</p>
  
  <pre><code>SELECT * FROM employees e1, employee_payrollhours
  WHERE `e1`.`Inserted_at` = 
      (SELECT MAX(e2.Inserted_at)
      FROM employees e2
      WHERE e1.Employee_Number = e2.Employee_Number)
      AND (`e1`.`Inserted_at` = 
      (SELECT MAX(e2.Inserted_at)
      FROM employees e2
      WHERE e1.Employee_Number = e2.Employee_Number)) = employee_payrollhours.Employee_Number;
  </code></pre>
  
  <p>Would someone please give me some direction on how to approach this problem to find the query I need?</p>
  
  <p>Thank you in advance.</p>