3 Replies - 555 Views - Last Post: 21 November 2016 - 02:44 PM

#1 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 17-May 13

MS SQL selecting a users score with multiple statements

Posted 20 November 2016 - 05:10 AM

Hi,
I have an MS SQL database which holds several scores for many different users ie

Nigels scores might be

Nigel 6
Nigel 7
Nigel 12
Mark 4

I can use this code to extract Nigels first score in the database. What I want is to extract his highest score in the database.

cmd.CommandText = ("select UserScore from Users where UserName='" + UserNameLoggedInLabel.Text() + "'")


Now I have used the code below in the past to specify an order but because this time I am having to check for multiple things I am getting a little lost. So how do I get my code to select Nigels highest score?
ORDER BY UserScore DESC


Thanks Nige.

Is This A Good Question/Topic? 0
  • +

Replies To: MS SQL selecting a users score with multiple statements

#2 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,916
  • Joined: 12-December 12

Re: MS SQL selecting a users score with multiple statements

Posted 20 November 2016 - 05:19 AM

MAX function
Was This Post Helpful? 1
  • +
  • -

#3 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 17-May 13

Re: MS SQL selecting a users score with multiple statements

Posted 20 November 2016 - 06:08 AM

Thanks andrewsw,
I have now got

cmd.CommandText = ("select MAX (UserScore) from Users where UserName='" + UserNameLoggedInLabel.Text() + "'")


:)
Was This Post Helpful? 0
  • +
  • -

#4 ybadragon  Icon User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: MS SQL selecting a users score with multiple statements

Posted 21 November 2016 - 02:44 PM

Another option for this is selecting TOP(1) UserScore orderd by UserScore DESC
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1