[RESOLVED] Simple question (Group By)
Hi everybody !
I want to Select all fields and group by one field, like the code below, but I got an error ?
I dont want to write all fields because there are too many...Is there a way to do that ?
VB Code:
strSQL = "SELECT * FROM Items WHERE BComm = ?" & " GROUP BY BCommNo"
Thanks in advance !
Re: Simple question (Group By)
Moved to correct forum
For a Group By every field in the Select list needs to either be in the Group By list, or be a calculated value in the Select list instead (eg: Sum(Field2)).
Re: [RESOLVED] Simple question (Group By)
Although I usually steer away from DISTINCT and usually tell users not to SELECT * (but instead put the column names)...
You could say:
SELECT DISTINCT * FROM SOMETABLE WHERE SOMECOL=123
Although why you would want to do that is beyond me ;)
Re: [RESOLVED] Simple question (Group By)
Quote:
Originally Posted by szlamany
. . . and usually tell users not to SELECT * (but instead put the column names). . .
I agree, unless you are going to use each and every column in the table (probably a very remote possibility) then only bring back the columns you need. This will reduce any overhead you may incur especially if you are bring back a lot of data.