Group By

Posted by Bravi under Sql Server on 9/27/2009 | Views : 1078 | Status : [Member] | Replies : 6
Select * from Emp group by deptno


whether above query is working fine or not . if it is work fine how it is work
if no why ?

Thanks&Regards,

B Ravi.




Responses

Posted by: Sriramnandha on: 5/20/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT * FROM EMPLOYEE WHERE EMPID NOT (SELECT EMPID

FROM EMPLOYEE GROUP BY EMPID HAVING COUNT(*)<1)

REGARDS


sriram

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/28/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Bravi

This is an Invalid Groupby Statement. Yo cannot use the Groupby with a "*". The GRoup by needs the names of the Fields. e.g


SELECT ID,Fname,LName FROM memyself
GROUP BY ID,Fname,Lname


Now your select statement must match the Group by Columns

Thank you for posting at DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bravi on: 9/28/2009 [Member] Starter

Up
0
Down
Thanks Vuyiswamb

Can we use forengin key column in group by ...

Select * from Emp group by deptno

here deptno is foreign key right..

Thanks&Regards,

B Ravi.

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/28/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Bravi

Yes you can.

Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bravi on: 9/28/2009 [Member] Starter

Up
0
Down
Thanks

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/28/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Thank you for posting at Dotnetfunda

Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response