SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 group by does not work
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

h0ppel
Starting Member

1 Posts

Posted - 04/22/2012 :  16:58:30  Show Profile  Reply with Quote
Hi,

does anybody know, why my comment does not work?

SELECT Employee.Lastname, Employee.Firstnme, EMP_ACT.Projno 
FROM Employee Join EMP_ACT On Employee.Empno = EMP_Act.Empno 
GROUP BY EMP_ACT.Projno 
HAVING COUNT(*) >= 3


this is the error:

SQL0119N An expression starting with "FIRSTNME" specified in a SELECT clause,
HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or
it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column
function and no GROUP BY clause is specified. SQLSTATE=42803

thanks

tkizer
Almighty SQL Goddess

USA
35017 Posts

Posted - 04/22/2012 :  18:09:49  Show Profile  Visit tkizer's Homepage  Reply with Quote
Your spelled Firstname wrong. It's missing an "a".

You're query needs to add aggregate functions though. Which LastName/FirstName combo do you want returned per Projno?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48050 Posts

Posted - 04/22/2012 :  21:32:19  Show Profile  Reply with Quote
seems like what you need is


SELECT e.Lastname, e.Firstname, ea.Projno 
FROM Employee e
Join (SELECT Empno,Projno FROM EMP_ACT 
GROUP BY Empno,Projno 
HAVING COUNT(*) >= 3
)ea
On e.Empno = ea.Empno


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


Edited by - visakh16 on 04/23/2012 11:28:09
Go to Top of Page

vinu.vijayan
Posting Yak Master

India
227 Posts

Posted - 04/23/2012 :  08:26:10  Show Profile  Reply with Quote
I agree with Visakh.
If you could post some DDL and sample data, we could provide better solutions rather than shooting in the dark like this.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 04/24/2012 :  06:16:51  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also note that this is MS SQL server forum for DB2 questions post at relevent forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000