• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

SQL GROUP BY function

I am trying to run a query where I group data in a database by a column called  "EEO1_Classification' in a table called 'Job_Title'.  I am to select a column called "Last_Name" from a table called "Employee."  I am a beginner at SQL syntax so please bear with me.

so I am to select the last names, and group them by 'Select Last_Name, EEO1_Classification.

thank you.
0
Winstink
Asked:
Winstink
  • 2
  • 2
1 Solution
 
KGNicklCommented:
You will have to select the names from the Employee table, then join the Employee table to the job_title table (is there userID or something that is in both table to join with?). Then you would group the data by EEO1_Classification'.
0
 
KGNicklCommented:
SELECT Employee.Last_Name, Job_Title.EE01_Classification
FROM Employee
LEFT JOIN Job_Title
ON Employee.EmployeeID = Job_Title.EmployeeID
GROUP BY Job_Title.EEO1_Classification

I'm assuming there is an EmployeeID field in my example that would be used to join. I don't know if this is true or not. But the SQL above should be close to what I think your wanting.
0
 
WinstinkAuthor Commented:
Job_ID is in both tables.

When I do either solution, it says:
Column 'Employee.Last_name' (or Last_Name) is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
0
 
qasim_mdCommented:
try this

SELECT Employee.Last_Name, Job_Title.EE01_Classification, count(*) as count
FROM Employee
LEFT JOIN Job_Title
ON Employee.EmployeeID = Job_Title.EmployeeID
GROUP BY Employee.Last_Name, Job_Title.EEO1_Classification
0
 
WinstinkAuthor Commented:
thank you
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now