SELECT (datfiles.name || "." || datfiles.extension) AS name, count(src_id) AS x, src_id FROM linkmap LEFT JOIN datfiles ON datfiles.id=src_id GROUP BY src_id ORDER BY x DESC SELECT (datfiles.name || "." || datfiles.extension) AS name, count(src_id) AS x, src_id FROM rawmap LEFT JOIN datfiles ON datfiles.id=src_id GROUP BY src_id ORDER BY x DESC