У меня всего 6 рядов.Когда я делаю запрос (скажем, SELECT * из таблицы), и у меня есть
- LIMIT 3 => FOUND_ROWS () дает 3 => извлекается 3 строки
- LIMIT 1, 3 => FOUND_ROWS () дает 4 => 3 строки получены
- LIMIT 2, 3 => FOUND_ROWS () дает 5 => 3 строки получены
- LIMIT 3, 3 => FOUND_ROWS ()дает 6 => 3 строки получены
- LIMIT 4, 3 => FOUND_ROWS () дает 6 => 2 строки получены
Любая идея, что является причиной этого странного поведения?
SQL QUERY
SELECT `places`.*, `category`.*, COUNT(places_reviews.place_id) AS num_reviews, (places_popularity.rating_1 + 2*places_popularity.rating_2 + 3*places_popularity.rating_3 + 4*places_popularity.rating_4 + 5*places_popularity.rating_5)/(places_popularity.rating_1 + places_popularity.rating_2 + places_popularity.rating_3 + places_popularity.rating_4 + places_popularity.rating_5) AS average_rating, FOUND_ROWS() AS num_rows FROM (`places`) JOIN `category` ON `places`.`category_id` = `category`.`category_id` LEFT JOIN `places_reviews` ON `places_reviews`.`place_id` = `places`.`id` LEFT JOIN `places_popularity` ON `places_popularity`.`place_id` = `places`.`id` WHERE `places`.`category_id` = 1 AND `places`.`name` LIKE '%%' GROUP BY `places`.`id` ORDER BY `id` desc LIMIT 3
Или в блоке:
SELECT `places`.*, `category`.*,
COUNT(places_reviews.place_id) AS num_reviews,
(places_popularity.rating_1 + 2*places_popularity.rating_2 + 3*places_popularity.rating_3 + 4*places_popularity.rating_4 + 5*places_popularity.rating_5)/(places_popularity.rating_1 + places_popularity.rating_2 + places_popularity.rating_3 + places_popularity.rating_4 + places_popularity.rating_5) AS average_rating, FOUND_ROWS() AS num_rows FROM (`places`)
JOIN `category` ON `places`.`category_id` = `category`.`category_id`
LEFT JOIN `places_reviews` ON `places_reviews`.`place_id` = `places`.`id`
LEFT JOIN `places_popularity` ON `places_popularity`.`place_id` = `places`.`id`
WHERE `places`.`category_id` = 1
AND `places`.`name` LIKE '%%'
GROUP BY `places`.`id`
ORDER BY `id` desc LIMIT 3