how to get max in sql
Hello,
I have a table, like this
ID, SendData, Sequence
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
0025 2005-12-02 00:00:00.000 1
0036 2005-12-05 00:00:00.000 1
I want to get the result, like this, get max(sequence) of ID
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
0036 2005-12-05 00:00:00.000 1
How to write this sql using one statement
thanks
[538 byte] By [
whygh] at [2007-11-11 7:26:06]

# 1 Re: how to get max in sql
I got a result, but it miss a row.
select id,senddate,sequence from myTable As A WHERE A.sequence = (SELECT MAX(B.sequence) from Mytable as B where B.id = A.id)
the Result is:
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
the last missed
0036 2005-12-05 00:00:00.000 1
Please tell me what is wrong. thanks
whygh at 2007-11-11 23:47:50 >

# 2 Re: how to get max in sql
What kind of database? If you're using MS Access, you can do this:
SELECT ID, FIRST(SendDate), MAX(Sequence)
FROM myTable
GROUP BY ID
SQL Server, unfortunately, does not have a FIRST function, so I don't know if you can do this with a single SELECT in SQL Server.