$params = [1, 3, 4, 6];
$clause = implode(',', array_fill(0, count($params), '?'));
$types = str_repeat('i', count($params));
$stmt = $mysqli->prepare("SELECT * FROM comments WHERE id IN ($clause)");
$stmt->bind_param($types, ...$params);
$stmt->execute();
$resArr = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
if(!$resArr) exit('No rows');
var_export($resArr);
$stmt->close();
рейтинг для каждой книги - COUNT записей
SELECT b.*, COALESCE(SUM(br.rating), 0) rating
FROM books b
LEFT JOIN books_rating br ON br.book_id = b.id
GROUP BY b.id