Re: problem with sql



TRY THIS:-


SELECT userid, max(datetime) as date
FROM UserLocationHistory
Group by userid
ORDER BY userid

Thanks
Hari
SQL Server MVP


"bhavik" <bhavik@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E157B034-E349-4EA8-B165-3BDC557EBE6F@xxxxxxxxxxxxxxxx
> hi
>
> I have problem with sql. I dont userstand what should I do.
> my problem is
>
> I have table UserLocationHistory
>
> I want those user who have latest date.
> I am fired sql like
>
> SELECT DISTINCT userid, datetime
> FROM UserLocationHistory
> ORDER BY userid, datetime DESC
> UserID datetime
> 80 1/5/2005
> 80 1/4/2005
> 80 1/2/2005
> 124 1/3/2005
> 124 1/2/2005
> 124 1/1/2005
> 130 1/3/2005
> 186 1/1/2005
>
>
> but I wnat this reasult like
>
> UserID datetime
> 80 1/5/2005
> 124 1/3/2005
> 130 1/3/2005
> 186 1/1/2005
>
> so please help me out
>
> regards,
> bhavik


.



Relevant Pages

  • Re: Hitting on indexes
    ... because SQL Server can use seek operations based on high-order columns. ... your indexes except the presumably clustered primary key index probably ... clustered, all 3 of you non-clustered can cover the UserId column, even ... though it is not explicitly included in the UserFirstName, UserAddress2 ...
    (microsoft.public.sqlserver.server)
  • Re: function as criteria for a query
    ... What i'm trying to do is base an SQL (stored procedure / view) query ... This method works in an MDB query like a charm! ... I have created a public variable called "userId" it stores the user id number ...
    (microsoft.public.access.queries)
  • Re: Query for an expert
    ... Can you post DDL for the tables and some sample data in SQL format? ... Consider renaming CaseId in the Cases table to CaseNumber, ... > UserId: Integer, autonumber ... > Attsid: Integer, autonumber ...
    (microsoft.public.sqlserver.programming)
  • SQL Express generate mismatched column aliases
    ... We are attempting to upgrade our application from MSDE 2000 to SQL ... the database views in the database are messed up. ... SELECT UserID AS ClassID, Password AS Custom, ClassID AS Disabled, ... MaxChannels AS UserID ...
    (microsoft.public.sqlserver.msde)
  • Re: WSS: Finding My Sites through SQL
    ... sites on a diferent server than the WSS server. ... foreach (XmlNode node in AllSites) ... and I came up with this SQL: ... Select @userId = tp_ID from UserInfo where tp_login like 'DOMAIN ...
    (microsoft.public.sharepoint.windowsservices)