您的位置:首页 > 数据库 > MySQL

MySQL 一对多查询,合并多的一方的信息

2015-11-27 20:49 579 查看
select
jdf_share.id_,jdf_share.title,
(select nickname from jdf_user where jdf_share.user_id_ = jdf_user.id_) as nickname , GROUP_CONCAT(jdf_file.imgurl_big) as imgurlbigs,GROUP_CONCAT(jdf_file.imgurl) imgurls,
if(isnull((select jdf_user_share_zan.tmstamp from jdf_user_share_zan
where jdf_user_share_zan.user_id_=1
and jdf_user_share_zan.share_id_=jdf_share.id_)),0,1)
as is_zan,IF (isnull((select jdf_collection.tmstamp from
jdf_collection where jdf_collection.user_id_=1
and jdf_collection.fk_id_=jdf_share.id_)),0,1)
as is_collect
from
jdf_share,jdf_user,jdf_file
where jdf_share.user_id_ = jdf_user.id_
and
jdf_file.flag=1
and
jdf_file.fk_id = jdf_share.id_
GROUP BY jdf_file.fk_id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: