SELECT `u`.`gid` AS `group_id`,
`g`.`name` AS `group_name`,
GROUP_CONCAT(DISTINCT `r`.`name` SEPARATOR ",") AS roles,
FROM (
SELECT `u`.`user` AS `user`, `u`.`gid` AS `gid`, `ru`.`id` AS `role`
FROM `users` AS `u`
LEFT JOIN `roles_users` AS `ru`
ON `u`.`user` = :user_id AND `ru`.`user` = `u`.`user`
UNION SELECT `u`.`user` AS `user`, `u`.`gid` AS `gid`, `rg`.`id` AS `role`
FROM `users` AS `u`
LEFT JOIN `roles_groups` AS `rg`
ON `u`.`user` = :user_id AND `rg`.`gid` = `u`.`gid`
) AS `ur`
INNER JOIN `groups` AS `g` ON `g`.`id` = `ur`.`gid`
LEFT JOIN `roles` AS `r` ON `r`.`id` = `ur`.`role`
SELECT *
FROM (
SELECT `fc`.`film_id`, GROUP_CONCAT(`c`.`title`) AS `titles`
FROM `film_crew` AS `fc`
JOIN `career_list` AS `c`
ON `fc`.`person_id` = :person_id AND `c`.`id` = `fc`.`career_id`
GROUP BY `fc`.`film_id`
) AS `t`
JOIN `films` AS `f` ON `f`.`id` = `t`.`film_id`
SELECT `v`.*
FROM (
SELECT `bank_id`, MAX(`date`) AS `date`
FROM `table`
WHERE `country` = :country_id AND `currency` = :currency_code
GROUP BY `bank_id`
) AS `d`
JOIN `table` AS `v`
ON `v`.`country` = :country_id AND `v`.`currency` = :currency_code
AND `v`.`bank_id` = `d`.`bank_id` AND `v`.`date` = `d`.`date`
domain_id int(9) unsigned NOT NULL default 0,
id int(9) unsigned NOT NULL,
...
deprecated datetime default NULL,
...
PRIMARY KEY (id,deprecated,domain_id)
ALTER TABLE `table`
ADD COLUMN `len` INT GENERATED ALWAYS AS (LENGTH(`field`)) VIRTUAL,
ADD INDEX `by_length` (`len`)
SELECT `c`.`id`
FROM `chair` AS `c`
LEFT JOIN `tickets` AS `t` ON `t`.`chair_id` = `c`.`id`
AND :desiredTime < (`t`.`time_from` + INTERVAL 30 MINUTE)
AND `t`.`time_from` < (:desiredTime + INTERVAL 30 MINUTE)
WHERE `t`.`chair_id` IS NULL