We help IT Professionals succeed at work.
Get Started

Group By Function in SQL

Kyle Witter
Kyle Witter asked
on
261 Views
Last Modified: 2012-05-11
I'm trying to create a view in MS SQL Management Studio, that groups data by two variables, but am having difficulty doing so.  As with my experience with PHP/SQL you can group by a column with little effort, but I continue to get an error that says "Column'dbo.Delivery.Job' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Basically I'm looking to remove duplicate entries in the outputted data, and if I could group by dbo.Job_Operation.Operation_Service & dbo.Job_Operation.Description it should eliminate the problem.  Attached is my current SQL Code.

Thank You!
SELECT     dbo.Delivery.Job, dbo.Delivery.Shipped_Date, dbo.Delivery.Shipped_Quantity, dbo.Job.Part_Number, dbo.Job.Description, dbo.Work_Center.Work_Center, 
                      dbo.Job_Operation.Operation_Service, dbo.Job_Operation.Description AS Route_Disc, dbo.Job_Operation.Est_Labor_Burden, 
                      dbo.Job_Operation.Est_Machine_Burden, dbo.Job_Operation.Est_GA_Burden, dbo.Job.Est_Labor, dbo.Job_Operation.Act_Labor_Burden, 
                      dbo.Job_Operation.Act_Machine_Burden, dbo.Job_Operation.Act_GA_Burden, dbo.Job.Act_Labor
FROM         dbo.Job INNER JOIN
                      dbo.Job_Operation ON dbo.Job.Job = dbo.Job_Operation.Job INNER JOIN
                      dbo.Job_Operation_Time ON dbo.Job_Operation.Job_Operation = dbo.Job_Operation_Time.Job_Operation INNER JOIN
                      dbo.Work_Center ON dbo.Job_Operation.Work_Center = dbo.Work_Center.Work_Center INNER JOIN
                      dbo.Delivery ON dbo.Job.Job = dbo.Delivery.Job

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE