2
I have a question. I have a table of categories:
CREATE TABLE `categorias` (
`id` int(10) UNSIGNED NOT NULL,
`parent_id` int(10) DEFAULT NULL,
`lft` int(10) DEFAULT NULL,
`rght` int(10) DEFAULT NULL,
`nome` varchar(255) DEFAULT NULL,
`publicado` int(11) NOT NULL DEFAULT '0',
`icon` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
And a product table:
CREATE TABLE `produtos` (
`id` int(11) NOT NULL,
`titulo` varchar(255) DEFAULT NULL,
`data` date DEFAULT NULL,
`categoria_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Where products.categoria_id is a foreign key from the table of categories. The category table has categories and subcategories, and the.parent_id category references a.id category to indicate that it is a daughter of the same.
I need to export the product table with a JOIN picking 3 first levels of the categories, and do not know which function to use for better suitability.
Result must be: PRODUCT NAME - PRODUCT ID - LEVEL 1 CATEGORY NAME - LEVEL 2 CATEGORY NAME - LEVEL 3 CATEGORY NAME - DATE
Can you help me?
Sensational, Rovann. That’s right, thank you very much!
– michelmfreitas