Link to home
Start Free TrialLog in
Avatar of cdhbs
cdhbs

asked on

select text field in query with aggregate function

How do I include a text (or ntext) field in a query that uses an aggregate function

eg

SELECT textField, someOtherField, COUNT(anotherFieldAgain) AS Total
FROM tblTable
GROUP BY textField, someOtherField

In MS access I could use the FIRST or LAST function to do this (on a SQL Server back-end) - and not include it in the group by clause.  How do I do this in SQL Server?
SOLUTION
Avatar of arbert
arbert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdhbs
cdhbs

ASKER

It's not so much that I want to group on the field.  What I'm doing is counting how many records there are in related tables and outputting all the data in this table.  Maybe I could count the related records in a subquery?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial