Mysql多对多查询、列合并实例命令:
1. mysql联合查询方法一
SELECT md_pictures.picid,md_pictures.sid,md_pictures.filename,md_pictures.comments,md_pictures.browse,
md_subject.name,md_subject.subname,md_subject.description,md_subject.pictures,md_subject.pageviews
FROM
`md_pictures`,`md_subject`
where
md_pictures.sid=md_subject.sid and md_pictures.status=1;
2. 联合查询方法二
select
md_subject.sid, md_subject.name,md_subject.subname,md_subject.pageviews, md_subject.pictures,group_concat(md_pictures.filename) as filename
FROM
`md_subject`
left join
`md_pictures`
on
md_pictures.sid = md_subject.sid
group by md_subject.sid
limit 10;
3.mysql多列合并命令
select
sid, name,group_concat(filename) as filename
FROM
`md_pictures`
group by sid //group_concat()必须和group by一起用
limit 10;