Solved

SQL GROUP BY function

Posted on 2011-03-15
5
348 Views
Last Modified: 2012-05-11
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
Comment
Question by:Winstink
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:KGNickl
ID: 35140501
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
 
LVL 5

Expert Comment

by:KGNickl
ID: 35140555
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
 
LVL 2

Author Comment

by:Winstink
ID: 35140741
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
 
LVL 4

Accepted Solution

by:
qasim_md earned 500 total points
ID: 35140782
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
 
LVL 2

Author Closing Comment

by:Winstink
ID: 35140805
thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question