Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select rows from partition in MySQL

I made partition my 300MB table and trying to make select query from p0 partition with this command

SELECT * FROM employees PARTITION (p0);

But I am getting following error

ERROR 1064 (42000): You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near '(p0)' at line 1

How to write select query to get data from specific partition?

like image 991
Kad Avatar asked Jan 01 '13 16:01

Kad


People also ask

How do I select multiple rows in MySQL?

To select last two rows, use ORDER BY DESC LIMIT 2.

How do I find rows in MySQL?

Getting MySQL row count of all tables in a specific database First, get all table names in the database. Second, construct an SQL statement that includes all SELECT COUNT(*) FROM table_name statements for all tables separated by UNION . Third, execute the SQL statement using a prepared statement.


2 Answers

Actually since MySQL 5.6 the supported syntax is:

SELECT * FROM table PARTITION (partitionName);
like image 189
rudygodoy Avatar answered Sep 24 '22 22:09

rudygodoy


The correct form of the query is as below it works for me fine.

select * from employees partition (`p0`);
like image 27
Omer Mohamed Nafaal Avatar answered Sep 24 '22 22:09

Omer Mohamed Nafaal