MySQL结果包含多行

时间:2015-02-02 08:56:23

标签: mysql

好吧,我有这段代码可以帮助我获取有关帖子的详细信息,例如文本状态,用户名,日期,编辑日期等,但问题是我只能从这个函数获得一行,怎么可能要获取多行?

begin
    declare ipost text;

    select concat('{"response":1,"posts":[',
            '{',
            '"status":"',   data_comment.comment,'",',
            '"date":"',     data_datetime.time,'",',
            '"edited":"',   data_datetime.edited,'",',
            '"user":"',     concat(data_user_data.name,' ',data_user_data.lastname),'",',
            '"photo":', '{"', group_concat(data_photo.name separator '","'),'"}'
            '}'
    ,']}') 
    into ipost
    from data_post
        inner join data_user_data on data_user_data.id = data_post.id_user
        inner join data_datetime on data_datetime.id = data_post.id_date
        inner join data_comment on data_comment.id = data_post.id_comment
        inner join data_photo
        inner join fk_post__photo on fk_post__photo.id_post = data_post.id 
            and fk_post__photo.id_photo = data_photo.id
    group by data_post.id
    desc
    limit 4;


    if(ipost is null) then
        return '{"response":0}';
    else
        return ipost;
    end if;

end

修改

replace

inner join data_photo
inner join fk_post__photo on fk_post__photo.id_post = data_post.id 
    and fk_post__photo.id_photo = data_photo.id

with

inner join fk_post__photo on fk_post__photo.id_post = data_post.id 
inner join data_photo on data_photo.id = fk_post__photo.id_photo

0 个答案:

没有答案