Microsoft
Software
Hardware
Network
Question : SQL Query - displaying latest entry per user
I have a query that I want to produce the latest entry(visit) for each of the user. In my head the query goes like this: For each user, show me the most recent visit that they had and all of the information from the visit. Given that there are one to many visits per user in this table. How can I return only the most recent visits without have to do some crazy joins? Is there a more simple way of structuring this query?
Here is the table structure:
Visit {
id int (Primary Key)
visit_date date
user_id int (foreign key)
field1 nvarchar(255)
field2 nvarchar(255)
...
}
To me it looks like a classic case of combining aggregate function with non-aggregate functions of the same table.
Answer : SQL Query - displaying latest entry per user
SELECT *
FROM Visits v
WHERE v.Visit_Date = (SELECT max(Visit_date) from visits v1 where v1.User_ID = v.User_ID )
Random Solutions
SBS 2003 Error - Windows could not start because of an error in the software. Please report this problem as : load needed DLLs for kernel.
MS Access onto a websever
WHAT IS AN ILIST,IDATASOURCE,IENUMERA<wbr />BLE
Detecting Drag of a CListCtrl Header Column Divider
Is there a cmd to see active sessions in SQL 2005?
T-SQL script to force users out of a database
Correct syntax for SQL between-like query
How do I set up Exchange 2007 Activesync to work with PDAs that can sync to Exchange Server
I need to increase the size of an SBS 2003 system partition
Using VBA to transfer CSV in AC07