Value of another field in the row that contains MAX(field)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Value of another field in the row that contains MAX(field)

Post by Bill H »

Okay, that subject is clear as mud, but it's the best I could do.

I have a table with two fields: "Seq" which is an int, and "Typ" which is an ENUM('Q','A'). (There's more than those two, but...) I know how to write a query to find out the maximum value for "Seq" but I don't really care about that value. What I want to know is the value of "Typ" in the row that contains that maximum value. Is there a single query to do that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT `Typ` FROM `table` ORDER BY `Seq` DESC LIMIT 1
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Duh. I keep forgetting how useful LIMIT is.
Thank you so much
Post Reply