Partition Selection Any valid query against a partitioned table can be rewritten with a  PARTITION  option to restrict the result to one or more desired partitions. You can use  WHERE  conditions,  ORDER BY  and  LIMIT  options, and so on. You can also use aggregate functions with  HAVING  and  GROUP BY  options. Each of the following queries produces a valid result when run on the  employees  table as previously defined: Statements using partition selection can be employed with tables using any of the supported partitioning types. When a table is created using  [LINEAR] HASH  or  [LINEAR] KEY  partitioning and the names of the partitions are not specified, MySQL automatically names the partitions  p0 ,  p1 ,  p2 , ...,  p N-1 , where N  is the number of partitions. For subpartitions not explicitly named, MySQL assigns automatically to the subpartitions in each partition  p X  the names  p X sp0 ,  p X sp1 ,  p X sp2 , ...,  p X sp M-1 , where  M  is the number of subpartitions. When executing against this table a  SELECT  (or other SQL statement for which explicit partition selection is allowed), you can use these generated names in a  PARTITION  option, as shown here: mysql>  CREATE TABLE employees_sub ( -> id INT NOT NULL AUTO_INCREMENT, -> fname VARCHAR(25) NOT NULL, -> lname VARCHAR(25) NOT NULL, -> store_id INT NOT NULL, -> department_id INT NOT NULL, -> PRIMARY KEY pk (id, lname) ->  ) -> PARTITION BY RANGE(id) -> SUBPARTITION BY KEY (lname) -> SUBPARTITIONS 2 ( -> PARTITION p0 VALUES LESS THAN (5), -> PARTITION p1 VALUES LESS THAN (10), -> PARTITION p2 VALUES LESS THAN (15), -> PARTITION p3 VALUES LESS THAN MAXVALUE ->  ); Query OK, 0 rows affected (1.14 sec) mysql>  SELECT * FROM employees PARTITION (p0, p2) -> WHERE lname LIKE ’S%’; 2 rows in set (0.00 sec) mysql>  SELECT id, CONCAT(fname, ’ ’, lname) AS name -> FROM employees PARTITION (p0) ORDER BY lname; 4 rows in set (0.06 sec) mysql>  SELECT store_id, COUNT(department_id) AS c -> FROM employees PARTITION (p1,p2,p3) -> GROUP BY store_id HAVING c > 4; 2 rows in set (0.00 sec) +----+-------+-------+----------+---------------+ | id | fname | lname | store_id | department_id | +----+-------+-------+----------+---------------+ | 4 | Jim | Smith | 2 | 4 | | 11 | Jill | Stone | 1 | 4 | +----+-------+-------+----------+---------------+ +----+----------------+ | id | name | +----+----------------+ | 3 | Ellen Johnson | | 4 | Jim Smith | | 1 | Bob Taylor | | 2 | Frank Williams | +----+----------------+ +---+----------+ | c | store_id | +---+----------+ | 5 | 2 | | 5 | 3 | +---+----------+ 4710