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
 [solved] Grouping by name

Author  Topic 

sqlconfused
Yak Posting Veteran

50 Posts

Posted - 2014-11-03 : 20:01:42
Hi, I know this is a simple solution but I don't know how to accomplish it.

auditing
========
username ip agent thedate

me | 99.250.xx.159 | Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0 | 2014-11-03 08:48:28.000
you | 70.51.24.2 | Mozilla/5.0 (Windows NT 5.1; rv:33.0) Gecko/20100101 Firefox/33.0 2014-11-03 16:07:01.000
him | 99.250.xx.163 | Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 | 2014-11-03 16:48:37.000
her | 99.250.xx.163 | Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 2014-11-03 16:48:37.000
her | 70.27.xx.157 | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0 | 2014-11-03 17:16:49.000


My SQL query is:
SELECT * FROM auditing order by username

which shows me user activity by username in alphabetical order

but what I'd like to do is be able to group the results by username and order by date so that in the example above "her" would display the two activity results in chronological order.

essentially something like:

SELECT * FROM auditing order by usern DESC group by username

however I can't do this, but I know that you can

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-11-04 : 00:51:05
[code]select *
from autiting
order by username
,thedate[/code]
Go to Top of Page

sqlconfused
Yak Posting Veteran

50 Posts

Posted - 2014-11-05 : 23:36:42
Very simple.. thank you.
Go to Top of Page
   

- Advertisement -