|
Home > Archive > MS SQL Server MSEQ > November 2005 > SQL HELP WITH LAST TIME ONLY
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SQL HELP WITH LAST TIME ONLY
|
|
|
| I have got a SQL query that get information from different databases,
I have all the information that I need but now I want the last information
I have three columns they are the following
Number
Durations
Date and time
I want to only select the last day and time from each records, at the moment
I have duplicate with the same numbers.
e.g
Namber Durations Dat
e and time
23 4:53 2005-11-17 16:38:15
23 9:21 2005-11-21 14:22:15
23 21:54 2005-11-25 17:41:21
So I just want the last date (as you can see below) not all three as you can
see above
Namber Durations Dat
e and time
23 21:54 2005-11-25 17:41:21
| |
| Hugo Kornelis 2005-11-29, 8:24 pm |
| On Mon, 28 Nov 2005 04:13:07 -0800, TYE wrote:
>I have got a SQL query that get information from different databases,
>
>I have all the information that I need but now I want the last information
>
>I have three columns they are the following
>
>Number
>Durations
>Date and time
>
>I want to only select the last day and time from each records, at the moment
>I have duplicate with the same numbers.
>
>e.g
>
> Namber Durations Dat
e and time
>
>23 4:53 2005-11-17 16:38:15
>23 9:21 2005-11-21 14:22:15
>23 21:54 2005-11-25 17:41:21
>
>So I just want the last date (as you can see below) not all three as you can
>see above
>
>
> Namber Durations Dat
e and time
>
>23 21:54 2005-11-25 17:41:21
Hi TYE,
For just one row with the last date and time:
SELECT TOP 1 Number, Durations, [Date and time]
FROM YourTable
ORDER BY [Date and time] DESC
For the last date and time of each Number:
SELECT t.Number, t.Durations, t.[Date and time]
FROM YourTable ASt
WHERE NOT EXISTS
(SELECT *
FROM YourTable AS t2
WHERE t2.Number = t.Number
AND t2.[Date and time] = t.[Date and time])
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
|
|
|
|
|