Mega Code Archive

 
Categories / MySQL / Aggregate Functions
 

Use the CONCAT( ) expression with MAX( ) to find the value with the largest population part

mysql> mysql> CREATE TABLE states     -> (     ->  name            VARCHAR(30) NOT NULL,   # state name     ->  abbrev          CHAR(2) NOT NULL,               # 2-char abbreviation     ->  statehood       DATE,                                   # date of entry into the Union     ->  pop                     BIGINT,                                 # population as of 4/1990     ->  PRIMARY KEY (abbrev)     -> ); Query OK, 0 rows affected (0.00 sec) mysql> SELECT MAX(CONCAT(LPAD(pop,8,' '),name)) FROM states; +-----------------------------------+ | MAX(CONCAT(LPAD(pop,8,' '),name)) | +-----------------------------------+ | NULL                              | +-----------------------------------+ 1 row in set (0.00 sec) mysql> mysql> drop table states; Query OK, 0 rows affected (0.00 sec)