GROUP BY

  • select #temp1.*,#temp2.*

    FROM #temp2 left outer join #temp1 on #temp1.EmployeeID=#temp2.EmpID

    How can i do a group by EmpId here.

  • Start with this:

    select

    rightt.*,

    leftt.*

    FROM

    #temp2 leftt

    left outer join #temp1 rightt

    on rightt.EmployeeID = leftt.EmpID

    GROUP BY

    leftt.EmpID

    Some changes I'd make would be to explicitly identify the columns being returned. Also, are you aggregating any of the fields?

    😎

  • NO, tht will not do.

    it gives error for many columns

    Column '#temp2.EmpIDis invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

  • A GROUP BY assumes you are aggregating some data in your select statement. That was the question I also asked in my previous post.

    Now my question is, what are you trying to accomplish with this query?

    😎

  • both temp tables already has some aggregated values in that, now am trying to group them by empid.

  • I am going to need more to help you out. Please read this article, it will show you how to help up help you:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    😎

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply