SELECT tb_infotype.*, tb_info.* FROM tb_infotype, tb_info
WHERE tb_infotype.infotype_pid = 'variable' AND tb_info.info_type = tb_infotype.infotype_idvariable就是你传SQL的infotype_id值,如果是或的关系,就(tb_infotype.infotype_pid = 'variable' OR tb_infotype.infotype_pid = 'variable')
WHERE tb_infotype.infotype_pid = 'variable' AND tb_info.info_type = tb_infotype.infotype_idvariable就是你传SQL的infotype_id值,如果是或的关系,就(tb_infotype.infotype_pid = 'variable' OR tb_infotype.infotype_pid = 'variable')
`infotype_id` int unsigned NOT NULL auto_increment,
`infotype_title` varchar(20),
`infotype_pid` int,
PRIMARY KEY (`infotype_id`)
) TYPE=MyISAM;CREATE TABLE `tb_info` (
`info_id` int unsigned NOT NULL auto_increment,
`info_type` int,
`info_title` varchar(20),
PRIMARY KEY (`info_id`)
) TYPE=MyISAM;INSERT INTO `tb_infotype` VALUES
( 1 , '新闻中心', 0),( 2 , '公司新闻', 1),( 3 , '行业新闻',1),( 4 , '新闻1', 2),
( 5 , '新闻2', 3),( 6 , '新闻3', 2),( 7 , '新闻4', 3),( 8 , '新闻5', 2),
(10 , 'FG', 6),(11 , 'aaa', 2),(12 , 'bbb', 2);INSERT INTO `tb_info` VALUES
(1 ,5, 'ppc'),(2 ,5, 'a'),(3 ,4, 'q'),(4 ,5, 's'),
(5 ,5, 'w'),(6 ,4, 'e'),(7 ,5, 'r'),(8 ,7, 'SSS'),
(9 ,8, 'aaa'),(10 ,8, '你你你你你你你你你你你你你我'),
(11 ,4, ' 友谊第一,争什么争。'),(12 ,4, 'asdf'),
(13 ,4, 'asdfasd'),(14 ,8, 'adfasd'),
(15 ,5, 'asdfa'),(16 ,4, 'adfasd'),
(17 ,6, '飞机阿利克等级分三大法三点开发间伐三点附近'),
(18 ,6, '飞机阿地开发就阿飞机阿地开发间阿');SELECT td.* FROM `tb_infotype` ta
LEFT JOIN `tb_infotype` tb ON ta.`infotype_id` = tb.`infotype_pid`
LEFT JOIN `tb_infotype` tc ON tb.`infotype_id` = tc.`infotype_pid`
LEFT JOIN `tb_info` td ON tc.`infotype_id` = td.`info_type`
WHERE tb.`infotype_title` = '公司新闻' AND td.`info_id` IS NOT NULL;drop table `tb_infotype`;
drop table `tb_info`;