?
Solved

SQL GROUP BY function

Posted on 2011-03-15
5
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

650 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