我建了2个表(文章,类别) 我怎样才能输出所有类别及其相关文章 例如:
类别 - >移动
文章 - > 1-samsung galaxy s3,2-samsung galaxy s4评论,3-samsung note 3
然后
类别 - >膝上型
articls - > 1-hp pavilion g6,2-lenovo 2014,3-dell inspiron15r
......等所有其他类别
CREATE TABLE IF NOT EXISTS `articles` (
`art_id` int(30) NOT NULL AUTO_INCREMENT,
`relcat_id` int(30) NOT NULL,
`art_title` varchar(250) NOT NULL,
`art_subtitle` varchar(250) NOT NULL,
`art_desc` text NOT NULL,
`art_snippet` text NOT NULL,
`art_tags` varchar(250) NOT NULL,
`art_download` text NOT NULL,
`art_instructor` varchar(250) NOT NULL,
`art_dt` varchar(250) NOT NULL,
PRIMARY KEY (`art_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `categories` (
`cat_id` int(30) NOT NULL AUTO_INCREMENT,
`cat_name` varchar(250) NOT NULL,
`cat_desc` text NOT NULL,
`cat_ref` varchar(250) NOT NULL,
`cat_img` varchar(250) NOT NULL,
PRIMARY KEY (`cat_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
我使用group_concat尝试了以下查询,但没有工作
select relcat_id,GROUP_CONCAT(art_id),art_title,art_subtitle,art_desc,art_tags,art_download,cat_name,cat_img from articles left join categories on articles.relcat_id=categories.cat_id where relcat_id=1 group by relcat_id