SQL query

Hey

I have this SQL query:

select all SMS_UserMachineIntelligence.NumberOfLogins
            ,SMS_UserMachineIntelligence.MachineResourceName
            ,SMS_UserMachineIntelligence.UniqueUserName from v_UserMachineIntelligence AS SMS_UserMachineIntelligence

Example data:

NumberOfLogins   MachineResourceName UniqueUserName
47      TPC72039      fasa
1      TPC72039      rilv
14      TPC72557      xynge
3      TPC72557      dddd
140      BB21229            ana
60      BB21229            pana

I need to change the SQL to return - only the MachineResouceName with highest NumberOfLogins:

47      TPC72039      fasa
14      TPC72557      xynge
140      BB21229            ana

Thanks in advance

Mike
LVL 1
mikeydkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try:

select Max(SMS_UserMachineIntelligence.NumberOfLogins) AS NumberOfLogins
       ,SMS_UserMachineIntelligence.MachineResourceName
       ,SMS_UserMachineIntelligence.UniqueUserName 
from v_UserMachineIntelligence AS SMS_UserMachineIntelligence 
group by SMS_UserMachineIntelligence.MachineResourceName
       ,SMS_UserMachineIntelligence.UniqueUserName 
order by SMS_UserMachineIntelligence.MachineResourceName
       ,SMS_UserMachineIntelligence.UniqueUserName 

Open in new window


»bp
0
NerdsOfTechTechnology ScientistCommented:
select t1.NOL, umi.UniqueUserNam, umi.UniqueUserName
FROM v_UserMachineIntelligence umi
INNER JOIN
(SELECT MAX(NumberOfLogins) AS NOL, MachineResourceName
FROM v_UserMachineIntelligence
GROUP BY MachineResourceName) t1
ON  t1.NOL = umi.NumberOfLogins AND t1.MachineResourceName = umi.MachineResourceName

Open in new window

0
mikeydkAuthor Commented:
Bill Prew> Still getting multiple lines with the same MachineResourceName
0
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

NerdsOfTechTechnology ScientistCommented:
typo sorry:

select t1.NOL, umi.MachineResourceName, umi.UniqueUserName
FROM v_UserMachineIntelligence umi
INNER JOIN
(SELECT MAX(NumberOfLogins) AS NOL, MachineResourceName
FROM v_UserMachineIntelligence
GROUP BY MachineResourceName) t1
ON  t1.NOL = umi.NumberOfLogins AND t1.MachineResourceName = umi.MachineResourceName

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
Still getting multiple lines with the same MachineResourceName

Doh, silly me.  Yes, I read it slightly simpler than you meant it, my fault.

Looks like you have plenty of other options now, I'm sure you'll get what you need by the time I could adjust.


»bp
0
mikeydkAuthor Commented:
select t1.NOL, umi.MachineResourceName, umi.UniqueUserName
FROM v_UserMachineIntelligence umi
INNER JOIN
(SELECT MAX(NumberOfLogins) AS NOL, MachineResourceName
FROM v_UserMachineIntelligence
GROUP BY MachineResourceName) t1
ON  t1.NOL = umi.NumberOfLogins AND t1.MachineResourceName = umi.MachineResourceName
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.