Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 GROUP BY

Author  Topic 

dcarva
Posting Yak Master

140 Posts

Posted - 2003-09-25 : 10:41:59
Hello, I have the following stored proc:

SELECT i.ProductId, i.ProductDesc, i.ProductPrice, i.ProductPicture, i.ProductPictureSize, c1.Category, c2.Category, c3.Category, i.ProductColorCode
FROM Cart_Inventory AS i
FULL OUTER JOIN Cart_Category1 AS c1 ON c1.Id = i.ProductCategory1
FULL OUTER JOIN Cart_Category2 AS c2 ON c2.Id = i.ProductCategory2
FULL OUTER JOIN Cart_Category3 AS c3 ON c3.Id = i.ProductCategory3
WHERE i.ProductDesc LIKE '%' + @Search + '%'
OR ProductId LIKE '%' + @Search + '%'
GROUP BY c1.Category, c2.Category, c3.Category

It doesn't compile in SQL Server because it states that I have not included all of the fields in the select statement into the GROUP BY clause. But I only want to group on the three fields I have above. Do I have to group on all fields in the select statement?

Thanks!

JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2003-09-25 : 10:46:51
Since you are not aggregating any data (i.e. SUM() or COUNT()) why do you need the group by in the first place?

Justin

"Look at it out there orbiting like it's so cool, we will rule it with an army of replicants!"
Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2003-09-25 : 10:49:39
Hmmm...I think wasn't understand group by then...

I have some records like this:

Category1 category2 category3
---------------------------------
1 1 3
2 2 4
1 1 3
2 2 4

I wanted to ensure that the were displayed in this order...

1 1 3
1 1 3
2 2 4
2 2 4

Thanks for your reply!
Go to Top of Page

JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2003-09-25 : 10:51:05
Then change your "Group By" to "Order By" and you should be good to go.

"Look at it out there orbiting like it's so cool, we will rule it with an army of replicants!"
Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2003-09-25 : 10:53:01
Uh...right. That make sense. I don't know what I was thinking! THANKS!
Go to Top of Page
   

- Advertisement -