MagePsycho
8/7/2017 - 6:49 PM

MySQL: Dynamic Table + SQL

MySQL: Dynamic Table + SQL

-- @author Raj KB
-- @website http://blog.magepsycho.com

SET @STORE_ID = 7;
SET @CATALOG_FLAT_TABLE = CONCAT('catalog_product_flat_', @STORE_ID);
SET @QUERY = CONCAT('SELECT * FROM ', @CATALOG_FLAT_TABLE, ' LIMIT 10');
PREPARE stmt FROM @QUERY;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;