INSERT ... WHERE
как вы это придумали? Синтаксис команды INSERT не предусматривает никакого WHERE https://dev.mysql.com/doc/refman/5.7/en/insert.html foreign key (test_id, question_id)
references test_question(test_id, question_id)
on delete cascade
от этого растет autoincrement
в случае ошибки можно просто напросто затереть данные, а не обновить и добавить
begin;
delete from `options` where `product_id` = 123;
insert into `options` (`name`, ...) values ('opt1', ...), ('opt2', ...);
commit;
... WHERE SC.id=666 HAVING fname='asd';
... WHERE SC.id=666 AND CONCAT(M.name,S.model,S.name)='asd';
PARTITION BY RANGE(YEAR(updated))
SUBPARTITION BY HASH(status)
SUBPARTITIONS 4 (
PARTITION p0 VALUES LESS THAN (2000),
PARTITION p1 VALUES LESS THAN (2010),
PARTITION p2 VALUES LESS THAN MAXVALUE
);
delimiter $$
drop function if exists `last_images_names`$$
create function `last_images_names` (aid int, ilimit int)
returns varchar(255)
reads sql data
begin
return (select group_concat(`name`) from (
select `name` from `images` where `album_id` = aid
order by `image_id` desc limit ilimit
) as _i);
end$$
delimiter ;
select `name`, last_images_names(`id`, 5) from `albums` order by `album_id` desc limit 10;
select u0.*, u1.*
from `user` as u0
inner join `user` as u1
on u1.id > u0.id and u1.show = 1
where
<some condition for u0>
limit 1;
select STAMP_HASH, group_concat(RATE_CODE) from m_rates group by RATE_CODE;
SELECT t1.`id`, COALESCE(t2.`index`, t1.`index`) as 'index'
FROM table_1 t1
LEFT JOIN table_2 t2 ON(t1.`id` = t2.`id`);