Home All Groups Group Topic Archive Search About
Author
25 Aug 2005 1:49 PM
rodchar
hey all,

i have 2 tables. i'm grouping on table1 i'd like to join this to table2
which would create 1 to 1 relationship. when add extra fields from table2 it
forces me to group by these fields as well. Can someone please explain this
concept to me?

thanks,
rodchar

Author
25 Aug 2005 1:54 PM
Aaron Bertrand [SQL Server MVP]
Could you give better specs?
http://www.aspfaq.com/5006



Show quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message
news:DAD412E6-9F72-42D2-8220-A8905E863944@microsoft.com...
> hey all,
>
> i have 2 tables. i'm grouping on table1 i'd like to join this to table2
> which would create 1 to 1 relationship. when add extra fields from table2
> it
> forces me to group by these fields as well. Can someone please explain
> this
> concept to me?
>
> thanks,
> rodchar
Author
25 Aug 2005 1:55 PM
Alejandro Mesa
Can you post what you are doing to have an idea of what you are talking about?


AMB

Show quote
"rodchar" wrote:

> hey all,
>
> i have 2 tables. i'm grouping on table1 i'd like to join this to table2
> which would create 1 to 1 relationship. when add extra fields from table2 it
> forces me to group by these fields as well. Can someone please explain this
> concept to me?
>
> thanks,
> rodchar
Author
25 Aug 2005 2:00 PM
David Gugick
rodchar wrote:
> hey all,
>
> i have 2 tables. i'm grouping on table1 i'd like to join this to
> table2 which would create 1 to 1 relationship. when add extra fields
> from table2 it forces me to group by these fields as well. Can
> someone please explain this concept to me?
>
> thanks,
> rodchar

All columns must appear in a group by clause unless you are using an
aggregate. From BOL: "When GROUP BY is specified, either each column in
any non-aggregate expression in the select list should be included in
the GROUP BY list, or the GROUP BY expression must match exactly the
select list expression."

If you were allowed to leave a column off the Group By clause, what
value would SQL Server use for the result set (assuming there were
multiple matches)?

You may be able to use a derived table to do what you want, but as Aaron
mentioned, we need some more details.


--
David Gugick
Quest Software
www.imceda.com
www.quest.com
Author
25 Aug 2005 7:02 PM
rodchar
thanks David and everyone this helped.

Show quote
"David Gugick" wrote:

> rodchar wrote:
> > hey all,
> >
> > i have 2 tables. i'm grouping on table1 i'd like to join this to
> > table2 which would create 1 to 1 relationship. when add extra fields
> > from table2 it forces me to group by these fields as well. Can
> > someone please explain this concept to me?
> >
> > thanks,
> > rodchar
>
> All columns must appear in a group by clause unless you are using an
> aggregate. From BOL: "When GROUP BY is specified, either each column in
> any non-aggregate expression in the select list should be included in
> the GROUP BY list, or the GROUP BY expression must match exactly the
> select list expression."
>
> If you were allowed to leave a column off the Group By clause, what
> value would SQL Server use for the result set (assuming there were
> multiple matches)?
>
> You may be able to use a derived table to do what you want, but as Aaron
> mentioned, we need some more details.
>
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>
>
Author
25 Aug 2005 2:03 PM
ML
The GROUP BY clause is explained here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sa-ses_9sfo.asp


ML

AddThis Social Bookmark Button