You cannot create nested table. And the thing on your mind is not a good idea to design table like that. You should have two tables (exactly three which holds the description if the category). One is for the product and the second table holds the category for each product. Example design would look like this,
CREATE TABLE Product ( ProductID INT PRIMARY KEY, ProductName VARCHAR(50) UNIQUE ); CREATE TABLE Category ( CategoryID INT PRIMARY KEY, CategoryName VARCHAR(50) UNIQUE ); CREATE TABLE Product_Category ( RecordD INT AUTO_INCREMENT PRIMARY KEY, CategoryID INT, ProductID INT, CONSTRAINT tb_uq UNIQUE(CategoryID, ProductID) );
and Populate Sample Records
INSERT Category VALUES (1, 'Fruit'); INSERT Category VALUES (2, 'Vegetable'); INSERT Product VALUES (1, 'Apple'); INSERT Product VALUES (2, 'Banana'); INSERT Product VALUES (3, 'Cabbage'); INSERT Product VALUES (4, 'Squash'); INSERT Product VALUES (5, 'Tomato'); INSERT Product_Category (CategoryID, ProductID) VALUES (1,1); INSERT Product_Category (CategoryID, ProductID) VALUES (1,2); INSERT Product_Category (CategoryID, ProductID) VALUES (2,3); INSERT Product_Category (CategoryID, ProductID) VALUES (2,4); INSERT Product_Category (CategoryID, ProductID) VALUES (1,5); INSERT Product_Category (CategoryID, ProductID) VALUES (2,5);
sample queries
-- NORMAL QUERY SELECT a.ProductName, c.CategoryName FROM Product a INNER JOIN Product_category b ON a.ProductID = b.ProductID INNER JOIN Category c ON b.CategoryID = c.CategoryID ORDER BY ProductName; -- If you want catgoryName to be comma separated SELECT a.ProductName, GROUP_CONCAT(c.CategoryName) CategoryList FROM Product a INNER JOIN Product_category b ON a.ProductID = b.ProductID INNER JOIN Category c ON b.CategoryID = c.CategoryID GROUP BY ProductName ORDER BY ProductName;