How to select rows from partition in MySQL

Depending on you MySql version, PARTITION keyword does not exist until MySQL 5.6.2. You would be using MySQL 5.5 or even 5.1, but not 5.6. In case, you are using MySQL 5.1, then you can do some workaround like below

SELECT partition, count(ID)
FROM
(
    SELECT ID,
      case when condition then p1
           when condition then p2
      .....
      end as partition

    FROM
      table
) s1
GROUP BY partition

Note : The above solution is just workaround to get you desire output.

You may also try this query to count total number of rows for your partition.

SELECT table_rows as 'count(*)' FROM information_schema.partitions WHERE table_schema = schema() and table_name ='employees' and partition_name = 'p0';

Note : you may change table_schema = schema() to table_schema = 'yourschema'


Actually since MySQL 5.6 the supported syntax is:

SELECT * FROM table PARTITION (partitionName);