February 22, 2011 at 7:20 pm
I have two Tables one called Employees and one called Job_Title. I am trying do a group by statement that Selects the Employees last name and Groups them by EEO1_Classification. My Employees Table and Job_Title tables are as follows:
EMPLOYEES JOB_Title
E_Id J_Id
LastName EEO1_Classification
FirstName JobTitle
Address JobDescription
PhoneNumber Exemption_NonExemptStatus
HireDate
Salary
age
Jobtitle
The Fllowing was my code that does not work:
Select Employees.LastName,Job_Title.EEO1_Classification
FROM Employees
INNER JOIN Job_Title
ON Employees.JobTitle=Job_Title.JobTitle
Group By EEO1_Classification;
Obviously I do not have something correct because I recieve the following error:
Major Error 0x80040E14, Minor Error 25515
> Select Employees.LastName,Job_Title.EEO1_Classification
FROM Employees
INNER JOIN Job_Title
ON Employees.JobTitle=Job_Title.JobTitle
Group By EEO1_Classification
In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions. [ Select clause = Employees,LastName ]
Any kind of help would be appreciated. I would like to understand the concept. I think it is easy enough to do with one table but I do not understand how to use both tables with the group command.
Thank you
February 22, 2011 at 7:51 pm
"GROUP BY" is normally used to aggregate data (e.g. to SUM amounts or to COUNT things). I suspect that you are using a more english interpretation of "GROUP" to mean clump similar things together.
You probably want to use "ORDER BY" instead of "GROUP BY"
February 23, 2011 at 3:22 am
Group by is used to grouping data or use some aggregate funtion.
if you are using group by then all the columns that are in the select list should be a part of gorup by or any aggregate funtion.
this will give result in your case
Select max(Employees.LastName),max(Job_Title.EEO1_Classification)
FROM Employees
INNER JOIN Job_Title
ON Employees.JobTitle=Job_Title.JobTitle
Group By EEO1_Classification;
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply