Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL query for this scenario

Posted on 2013-11-28
4
Medium Priority
?
180 Views
Last Modified: 2013-12-01
Hi guys,

Im sure the following can be done in a single query:

I have a table with usernames and dates when they were last active. I need a query to collect the username and the last date they were online. Each username can appear more than once and they will have various dates, ie:

Username            Date

John Smith            01/01/12
John Smith            03/11/12
John Smith            07/12/12
Simon Jones          11/06/13
Simon Jones          15/02/13
Simon Jones          18/09/13

Cheers,
Dean
0
Comment
Question by:deanlee17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 39683071
SELECT  `Username` , MAX(  `Date` )
FROM  `table_logins`
GROUP BY  `Username`
0
 
LVL 43

Expert Comment

by:Rob
ID: 39683073
That's assuming that the "Date" column is a date field.  If it is stored as text then you'll need to convert it to a date.  In MySQL for example you use str_to_date()
0
 

Author Comment

by:deanlee17
ID: 39683188
Yes it is in date field.

Perfect thanks.
0
 
LVL 43

Expert Comment

by:Rob
ID: 39683202
Great - let me know if you have any more issues :)
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question