0

グループ化する前にテーブル(コメント)を並べ替えようとしているので、という一時テーブルを作成し、comm_sortedタイムスタンプで並べ替えました。

ただし、それでも機能しません。

    $sql = "
select images.id,images.image as imageURL, images.fid as userID, user.name as userFullName, images.comment as feedDescription, images.sharedServices, stores.name as customerName, 
CONCAT('[', 
GROUP_CONCAT(
DISTINCT CONCAT('\"',likes.uid,'\"')),']') as likes , 
CONCAT('[', 
GROUP_CONCAT(
DISTINCT CONCAT('{\"userId\":\"',comm_sorted.uid,'\",\"comment\":\"',comm_sorted.comment,'\",\"timeStamp\":\"',comm_sorted.timestamp,'\"}') separator ','),']')  as comments FROM images 
LEFT JOIN stores on images.client_id=stores.id 
LEFT JOIN likes on images.id=likes.feedid 
LEFT JOIN (select * from comments order by timestamp DESC) as comm_sorted on images.id=comm_sorted.feedid  
LEFT JOIN user on images.fid=user.id WHERE images.fid=:userID group by images.id, user.name, images.image, images.comment, images.sharedServices, stores.name order by images.Timestamp 
DESC LIMIT $offset, $limit";
4

1 に答える 1

1

Barmar 氏に感謝 - ORDER BY comm_sorted.timestamp オプションを GROUP_CONCAT() 関数に入れることができます。一時クエリは必要ありません。質問は締め切りました。

于 2012-09-28T16:00:13.100 に答える