SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Repeated users...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 02/08/2013 :  06:59:11  Show Profile  Reply with Quote
i have two tables:
First one: Users with:
id int (primary)
name varchar

and a second user_register with:
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


Edited by - marcobranco1975 on 02/08/2013 06:59:48

Premature Yak Congratulator

22847 Posts

Posted - 02/08/2013 :  07:02:46  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
select name, max(date_usage) as date_usage from users
left join user_register on id_user = id
group by name


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000