montypython1
Technical User
Greetings,
How do I display fields that are not being grouped together using the "Select Distinct" SQL command?
My database is called "EmplTest" and it contains the following fields:
Emp_Key SSN Emplast Updated
------- ----------- ----------- ---------
4223 111-11-1111 ABLE 04/15/2001
4505 111-11-2222 BAKER 01/01/2002
4700 111-11-2222 BAKER 12/31/2005
etc.
I simply need to select the maximum "Emp_Key" [ MAX(Emp_Key) ] for all identical "SSN" records, but I need to display all the fields, not just the fields being grouped.
My desired output would look like this (notice Emp_Key "4505" does not display):
Emp_Key SSN Emplast Updated
------- ----------- ----------- ---------
4223 111-11-1111 ABLE 04/15/2001
4700 111-11-2222 BAKER 12/31/2005
When I use the following code, it gives me the maximum "Emp_Key" value and the "SSN", but does not display the associated fields:
SELECT DISTINCT ssn, MAX(Emp_Key) FROM EmplTest GROUP BY ssn ORDER BY ssn
When I use the following code, it generates an error message, since I am not grouping the additional fields:
SELECT DISTINCT ssn, MAX(Emp_Key), EmpLast, Updated FROM EmplTest GROUP BY ssn ORDER BY ssn
Before posting the question, I reviewed Tek-Tips thread184-1411960, and I initially thought that I should be using the "Select Distinct" SQL command, but maybe I'm barking up the wrong tree.
Any suggestions?
Thanks,
Dave Higgins
How do I display fields that are not being grouped together using the "Select Distinct" SQL command?
My database is called "EmplTest" and it contains the following fields:
Emp_Key SSN Emplast Updated
------- ----------- ----------- ---------
4223 111-11-1111 ABLE 04/15/2001
4505 111-11-2222 BAKER 01/01/2002
4700 111-11-2222 BAKER 12/31/2005
etc.
I simply need to select the maximum "Emp_Key" [ MAX(Emp_Key) ] for all identical "SSN" records, but I need to display all the fields, not just the fields being grouped.
My desired output would look like this (notice Emp_Key "4505" does not display):
Emp_Key SSN Emplast Updated
------- ----------- ----------- ---------
4223 111-11-1111 ABLE 04/15/2001
4700 111-11-2222 BAKER 12/31/2005
When I use the following code, it gives me the maximum "Emp_Key" value and the "SSN", but does not display the associated fields:
SELECT DISTINCT ssn, MAX(Emp_Key) FROM EmplTest GROUP BY ssn ORDER BY ssn
When I use the following code, it generates an error message, since I am not grouping the additional fields:
SELECT DISTINCT ssn, MAX(Emp_Key), EmpLast, Updated FROM EmplTest GROUP BY ssn ORDER BY ssn
Before posting the question, I reviewed Tek-Tips thread184-1411960, and I initially thought that I should be using the "Select Distinct" SQL command, but maybe I'm barking up the wrong tree.
Any suggestions?
Thanks,
Dave Higgins