Re: SQL HELP WITH LAST TIME ONLY
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 01:21:08 +0100
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 Date 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 Date 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)
.
- Prev by Date: Re: Merging mutliple rows from one table into columns in an other
- Previous by thread: Re: Merging mutliple rows from one table into columns in an other
- Index(es):
Relevant Pages
|
|