min(x), where is a char (string) type -- char(), varchar(), nchar(), nvarchar(), finds the lowest value in the group, based on SQL's string comparison rules:
- if two strings differ in length, the shorter is padded with SP characters (spaces) to the length of the longer.
- comparison proceeds left-to-right, character by character, according to the rule of the collation sequence in use.
- in comparisons, the value NULL compares lower than any non-null values (the ISO/ANSI SQL standard says that it is an implementation choice as to whether NULL collates lower or higher than any non-null value).
So, if you have a table
create table foo
(
myString varchar(16) not null ,
)
then running the query
select min(myString) from foo
will give you the same result set as if you executed
set rowcount 1
select myString
from foo
order by myString
set rowcount 0
You are basically ordering the set in ascending sequence and selecting the first value. MAX(), or course, gives you the inverse, ordering the set in descending sequence and selecting the first value.
MIN(Data)
on that table?? – BarbecueMIN(DATA)
would return "AA AB AC". – Mullins