SQL query question.
#1

Hey lads,

let's say there are 3 rows in the table:

Код:
Name ------ Money ------ WantedLevel

Test ------  1000  ------ 11
Test2 ------ 40000 ------ 20
Test3 ------ 1337  ------ 50
Now, for example, I want to get the highest Money and WantedLevel values stored in the database.

so I'd do it this way:

Код:
SELECT MAX(Money), MAX(WantedLevel) FROM `table`
and it'd give 40000, 50

But how do I also get the Name, which has the biggest Money and WantedLevel values? That the output would be Test2 - 40000, Test3 - 50

Is it possible to do it in the same query posted above? Or do I also to send several other queries, such like:

Код:
SELECT `Name` FROM `table` WHERE `WantedLevel` = 40000
etc.?

Thanks!
Reply
#2

Use a semicolon ; to send multiple queries in one line
Reply
#3

AFAIK multiple queries are disabled? click
Reply
#4

Quote:
Originally Posted by b3nz
Посмотреть сообщение
AFAIK multiple queries are disabled? click
Looks like indeed... Just do multiple queries then, that should be fine.
Reply
#5

As I'm not in a hurry to do this, I'll just wait a few days, maybe someone will come up with an idea. Anyway, thanks!
Reply
#6

It would be easier if you wanted that in 2 rows, but it can be done using nested queries:
http://sqlfiddle.com/#!9/945e5/7
Reply
#7

Thank you! This looks simple to modificate & add more fields to check.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)