Solved

SQL GROUP BY function

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now