Re: SQL HELP WITH LAST TIME ONLY



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)
.



Relevant Pages

  • Using SQL format function in Access 2003
    ... We've just converted our Access 2000 databases to Access 2003. ... SQL query: ... Prev by Date: ...
    (microsoft.public.access.queries)
  • SQL In 2 Databases
    ... I was wondering how i could get my simple SQL query to check through 2 ... Both databases are in c:\data\ ... both need to be search in table2 ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: SQL In 2 Databases
    ... >I was wondering how i could get my simple SQL query to check through 2 ... In maindata define a new View / Query which joins the real Table2 ...
    (microsoft.public.vb.general.discussion)
  • Re: Querying ODBC Tables
    ... databases of the same structure. ... have a table called customer. ... I want a SQL query that pulls back 21 records in total from ... the dataset containing the cross join of customer table and order ...
    (microsoft.public.access.queries)