UPDATE `tasks`
SET @id := `id`, `state` = 'in_work',
`work_start_time` = NOW(), `worker` = :pid
WHERE `state` = 'wait'
ORDER BY `create_time`
LIMIT 1;
SELECT * FROM `tasks` WHERE `id` = @id;
UPDATE `tasks` SET `state` = 'done' WHERE `id` = @id;
@id := `id`
SELECT *
FROM (
SELECT *, MATCH `text` AGAINST('database') AS `score`
FROM `articles`
) AS `t`
WHERE `score` > 0
ORDER BY `source` != 'auto', `score`
SELECT *
FROM (
SELECT *, MATCH `text` AGAINST('database') AS `score`
FROM `articles`
) AS `t`
WHERE `score` > 0
ORDER BY `score`+(`source` = 'auto')*0.5 DESC
SELECT `t1`.`usrid`, `t2`.`data`, `t2`.`postid`
FROM (
SELECT `usrid`, COUNT(*) AS `cnt`
FROM `posts`
WHERE `data` BETWEEN :start AND :end
GROUP BY `usrid`
ORDER BY `cnt` DESC
LIMIT 10
) AS `t1`
JOIN `posts` AS `t2` USING(`usrid`)
WHERE `t2`.`data` BETWEEN :start AND :end
ORDER BY `t1`.`cnt`, `t1`.`usrid`, `t2`.`data`
SELECT `ul`.`user_id`, `ul`.`name`, `ul`.`uid`, `ul`.`gender`
FROM `users_list` AS `ul`
JOIN `users_groups` AS `ug` ON `ul`.`user_id` = `ug`.`user_id`
JOIN `groups_list` AS `gl` ON `gl`.`group_id` = `ug`.`user_id`
WHERE `gl`.`uid` = :gid;
UPDATE `emails` SET `status` = 1 WHERE @id := `id` AND `status` = 0 ORDER BY RAND() LIMIT 1;
SELECT * FROM `emails` WHERE `id` = @id;
SELECT `prod`.`name`, `prod`.`price`,
GROUP_CONCAT(CONCAT(`atr`.`nameAttribute`, '=' , `val`.`attributeValue`) as `attribute`,
FROM `products` as `prod`
LEFT JOIN `productAttribute` as `atr` ON `prod`.`idProduct` = `atr`.`idProduct`
LEFT JOIN `attributeValue` as `val` ON `atr`.`idAttribute` = `val`.`idAttribute`
WHERE `prod`.`idCategory` = :idCategory
GROUP BY `prod`.`idProduct`;