Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Repeated users...

Author  Topic 

marcobranco1975
Starting Member

2 Posts

Posted - 2013-02-08 : 06:59:11
Hi.
i have two tables:
First one: Users with:
id int (primary)
name varchar

and a second user_register with:
id_user
date_usage DateTime

i need to get the list of users with the last access (not all the access.

i made this

select distinct name, date_usage from users
left join user_register on id_user = id

but i get a all users with all the access register...

i need only one per user with the last login


Any idea?

Thank's in advance

Marco

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-02-08 : 07:02:46
select name, max(date_usage) as date_usage from users
left join user_register on id_user = id
group by name

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -