Solved

SQL GROUP BY function

Posted on 2011-03-15
5
350 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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