connection->getQueryBuilder(); // SELECT all photos $query->select('f.fileid', 'f.etag')->from('memories', 'm'); // WHERE these photos are in the user's requested folder recursively $query = $this->joinFilecache($query, $root, true, false); // ORDER descending by fileid $query->orderBy('f.fileid', 'DESC'); // MAX 4 $query->setMaxResults(4); // FETCH tag previews $rows = $this->executeQueryWithCTEs($query)->fetchAll(); // Post-process foreach ($rows as &$row) { $row['fileid'] = (int) $row['fileid']; } return $rows; } }