Sunday, February 19, 2012

Efficiently refering to non-identifier fields on "one" side of joi

I have what is probably an elementary question, and will be grateful for you
r
help. I am just moving a database from Jet and learning SQL Server as I go.
In Jet, if I had a query doing aggregate functions on a one-many join, I
would often use First() and Last() on fields on the one side other than the
unique identifier, for efficiency. E.g., I would group on the one side by
Student ID, and refer to First([Student name]). This seems more efficient
than "GROUP BY [student name]", which would be redundant since I am already
grouping by Student ID; and more computationally efficient than Min() or
Max().
Question is, what's the efficient way to do this in SQL Server, since
First() and Last() are not available (which I understand is because SQL
Server more strictly adheres to the paradigm of the unordered set)? Thanks.
--DavidDavid
First() --SQL Server is MIN()
Last() --SQL Server is MAX()
"David Roodman" <DavidRoodman@.discussions.microsoft.com> wrote in message
news:C1F7D9F9-D540-421A-9943-C07B4FC6295C@.microsoft.com...
>I have what is probably an elementary question, and will be grateful for
>your
> help. I am just moving a database from Jet and learning SQL Server as I
> go.
> In Jet, if I had a query doing aggregate functions on a one-many join, I
> would often use First() and Last() on fields on the one side other than
> the
> unique identifier, for efficiency. E.g., I would group on the one side by
> Student ID, and refer to First([Student name]). This seems more efficient
> than "GROUP BY [student name]", which would be redundant since I am
> already
> grouping by Student ID; and more computationally efficient than Min() or
> Max().
> Question is, what's the efficient way to do this in SQL Server, since
> First() and Last() are not available (which I understand is because SQL
> Server more strictly adheres to the paradigm of the unordered set)?
> Thanks.
> --David

No comments:

Post a Comment