Answer the question
In order to leave comments, you need to log in
How to merge multiple tables?
CREATE TABLE IF NOT EXISTS `prefix_categories` (
`cat_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`parent_id` int(11) unsigned NOT NULL DEFAULT '0',
`num_sort` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`cat_id`),
UNIQUE KEY `slug` (`slug`),
UNIQUE KEY `num_sort` (`num_sort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `prefix_link` (
`link_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`parent_id` int(11) unsigned NOT NULL DEFAULT '0',
`num_sort` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`link_id`),
UNIQUE KEY `slug` (`slug`,`num_sort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `prefix_menu` (
`menu_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`slug` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`menu_id`),
UNIQUE KEY `slug` (`slug`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `prefix_pages` (
`page_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`parent_id` int(11) unsigned NOT NULL,
`num_sort` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`page_id`),
UNIQUE KEY `slug` (`slug`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `prefix_menu` (
`menu_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`slug` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`menu_id`),
UNIQUE KEY `slug` (`slug`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
INSERT INTO `prefix_menu` (`menu_id`, `slug`, `name`) VALUES (1, 'main', 'главное');
Answer the question
In order to leave comments, you need to log in
Combine like this:
SELECT 'pc' table_name, * FROM prefix_categories
UNION ALL
SELECT 'pl' table_name, * FROM prefix_link
UNION ALL
SELECT 'pm1' table_name, *, 0 parent_id, NULL num_sort FROM prefix_menu
UNION ALL
SELECT 'pp' table_name, * FROM prefix_pages
UNION ALL
SELECT 'pm2' table_name, *, 0 parent_id, NULL num_sort FROM prefix_menu;
Then you can use this as a subquery, by which to create a tree. But this is far from the best option.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question