UPDATE `trade_log` AS `tl`
JOIN `users` AS `u` ON `tl`.`tradeId` = ? AND `tl`.`status` = 'send'
AND `u`.`steam_id` = `tl`.`steamid_other`
SET `tl`.`status` = 'success', `u`.`balance` = `u`.`balance` + `tl`.`sum`
SELECT `steamid_other`, `sum`
FROM `trade_log`
WHERE `tradeId` = ? AND `status` = 'success'
SELECT `b`.`*`, `i`.`count`
FROM (
SELECT `ib`.`id_brand` AS `brand`, COUNT(*) AS `count`
FROM `item_brand` AS `ib`
JOIN `item` AS `i` ON `i`.`enabled` = 1
AND `i`.`id_category` IN (21,317,318)
AND `i`.`id` = `ib`.`id_item`
GROUP BY `ib`.`id_brand`
) AS `i`
JOIN `brand` AS `b` ON `b`.`id` = `i`.`id_brand`
ORDER BY `i`.`count` DESC
SELECT `b`.`id`, `b`.`title`, `b`.`description`, `b`.`public`,
(SELECT COUNT(*) FROM `likes` WHERE `boycottid` = :boycot_id) AS `likes`,
(SELECT COUNT(*) FROM `dislikes` WHERE `boycottid` = :boycot_id) AS `dislikes`,
(SELECT COUNT(*) FROM `subscriptions` WHERE `boycottid` = :boycot_id) AS `subscriptions`
FROM (
SELECT `id`, `title`, `description`, `public` FROM `boycotts` WHERE `id` = :boycot_id
) AS `b`