So this question might have already been answered, but it's a bit difficult to search for or even to ask it.
I want to query a table and filter it in a number of ways. In the example below, I want to figure out who the first employee was for each dept.
Example Table Below Table A
employee_id | dept_id | start_date | name | age | sex
1 | 1 | 1/5/2000 | Bill | 25 | m
2 | 2 | 2/5/2000 | Biff | 30 | m
3 | 2 | 3/6/2002 | Gil | 31 | m
4 | 2 | 3/7/2002 | Mar | 27 | f
5 | 3 | 1/5/2000 | Tina | 24 | f
6 | 3 | 1/5/2000 | Lin | 21 | f
So if I do SELECT dept_id, min(start_date) from Table A GROUP BY dept_id ORDER BY min(start_date)
I'll get
dept_id | start_date
1 | 1/5/2000
2 | 2/5/2000
3 | 1/5/2000
Which is correct information, except I need the other columns. I can't just add them to the SELECT statement because they aren't in the GROUP BY, and I can't just add them to the GROUP BY because then I won't get the correct results.
This comment sort of answered my question, but not fully SQL Select Distinct Values, but order by a different value because I tried doing a subquery inside a join and adding the fields in the SELECT, but it still wanted the fields to be in the GROUP BY.
Please Advise
EDIT: The results I'd like to get are
employee_id | dept_id | start_date | name | age | sex
1 | 1 | 1/5/2000 | Bill | 25 | m
2 | 2 | 2/5/2000 | Biff | 30 | m
5 | 3 | 1/5/2000 | Tina | 24 | f