SELECT
(SELECT COUNT(`id`) FROM `products` WHERE `category_id` = 34) AS `count1`,
(SELECT COUNT(`id`) FROM `products` WHERE `category_id` = 35) AS `count2`;
<?php
// buy.php пример
...
$pdo->begintransaction();
if (isset($product))
{
$que = "UPDATE `shops` SET `status` = 'Продано' WHERE `id` = ? AND `status` = ''";
$pre = $pdo->prepare($que);
$pre->execute([$product]);
if ($pre->rowCount())
{
// Товар куплен
}
else
{
// Статус был изменен другой транзакцией, либо това не найден
}
}
$pdo->commit();
...
?>
SELECT
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 12) AS `count_01`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 123) AS `count_02`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 1234) AS `count_03`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 12345) AS `count_04`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 123456) AS `count_05`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 1234567) AS `count_06`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 7654321) AS `count_07`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 765432) AS `count_08`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 76543) AS `count_09`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 7654) AS `count_10`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 765) AS `count_11`,
(SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 76) AS `count_12`
SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 543
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 5443
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 34567
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 211567
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 345688
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 123356
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 1433556
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 2355464
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 566967
UNION SELECT COUNT(`id`) FROM `user_shmots` WHERE `user_id` = 123133