WHERE
(tasks.project_id = ".$_SESSION['selected_menu_item_id']."
AND tasks.author_id = '".$USER['id']."'")
OR (".$_SESSION['selected_menu_item_id']." <b>is null</b>
AND tasks.author_id = '".$USER['id']."'")
select group_concat(if(v='a', c, null)) a,
group_concat(if(v='b', c, null)) b,
group_concat(if(v='c', c, null)) c
from (select value v, Count(value) c
from t1
group by value ) temp
SELECT Max(max_fast_jackpot, max_coinflip_jackpot)
FROM (
SELECT *,
(SELECT Coalesce(Max(won_amount), 0)
FROM `fast_games`
INNER JOIN `fast_bets` AS `winning_fast_bets`
ON `winning_fast_bets`.`id` =
`fast_games`.`winning_bet_id`
WHERE users.id = winning_fast_bets.user_id
AND `fast_games`.`state` = ?)
AS `max_fast_jackpot`,
(SELECT Coalesce(Max(won_amount), 0)
FROM `coinflip_games`
INNER JOIN `coinflip_bets` AS `winning_coinflip_bets`
ON `winning_coinflip_bets`.`id` =
`coinflip_games`.`winning_bet_id`
WHERE users.id = winning_coinflip_bets.user_id
AND `coinflip_games`.`state` = ?)
AS `max_coinflip_jackpot` )
FROM `users`
WHERE `id` = ?
)
UPDATE
sales as s
SET s.plan_payment_date = (SELECT
MAX(pay.payment_date)
FROM
payments pay
, payments_parts pp
WHERE pay.ID = pp.FK_payment
and s.ID = pp.FK_sale
)