Two fields in the SQL data table are associated with the same data table.
Temp structure of data table
-- Table "temp" DDLCREATE TABLE `temp` ( `page_id` bigint(20) DEFAULT NULL, `section_id` bigint(20) DEFAULT NULL, `visit_category_id` bigint(20) DEFAULT NULL, `cart_category_id` bigint(20) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Data Table category Structure
-- Table "category" DDLCREATE TABLE `category` ( `category_id` bigint(20) DEFAULT NULL, `category_name` varchar(128) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Business Requirements
Associate the temp and category tables to obtain the category_name corresponding to visit_category_id and cart_category_id.
Solution
select a.page_id,a.section_id,a.visit_category_id,b.category_name,a.cart_category_id,c.category_name from temp a left outer join category b on (a.visit_category_id=b.category_id) left outer join category c on (a.cart_category_id=c.category_id);
Query Result