mysql select row with min date 1

mysql select row with min date

SELECT t1.*
FROM employees t1
INNER JOIN (
    SELECT id, min(job_start) AS job_start FROM employees GROUP BY id
) t2 ON t1.id = t2.id AND t1.job_start = t2.job_start;

Here is what the above code is Doing:
1. The subquery is getting the minimum job_start date for each id.
2. The outer query is joining the employees table to the subquery on the id and job_start columns.

The result is a table that contains the first row for each id.

Similar Posts