DELIMITER $$
CREATE TRIGGER auto_inc_new_admin_logs
BEFORE INSERT ON new_admin_logs FOR EACH ROW
BEGIN
DECLARE new1 INT;
SELECT max(id) into new1 FROM new_admin_logs;
SET NEW.id = new1 + 1;
END$$
CREATE TRIGGER `update_users` AFTER UPDATE ON `users`
FOR EACH ROW
BEGIN
INSERT INTO payments(status_id, user_id, description, currency_id,
amount, bonus_amount, sum)
values('2' ,new.id, 'test', 643,
old.balance, old.balance+new.balance, new.balance);
END;
select ads.id, ads_meta.text, ads_images.path ...
from ads, ads_images, ads_meta
where ads_images.ads_id=ads.id and ads_meta.ads_id=ads.id
order by ads.id
select distinct pa.attribute_id , pa.text from product_attribute pa, product_category pb
where p.product_id = pa.product_id and p.category_id=8 and
pa.product_id not in (
select pa2.product_id from product_attribute pa2
where (pa2.attribute_id=9 and pa2.text=92) or (pa2.attribute_id=8 and pa2.text=55)
) and
not((pa.attribute_id=9 and pa.text=92) or (pa.attribute_id=8 and pa.text=55))
select distinct pa.attribute_id , pa.text from product_attribute pa, product_category pb, filtr_sess fs
where p.product_id = pa.product_id and p.category_id=8 and
pa.product_id not in (
select pa2.product_id from product_attribute pa2, filtr_sess s
where (pa2.attribute_id=s.id and pa2.text=s.text and s.sid=X)
) and fs.sid=X and pa.attribute_id <> fs.id and pa.text <> fs.text
UPDATE table1 SET col1 = col1+1
update table1 set col1=1 where col is null
, если второе - хватит и первой команды. select product_id as id, products.name,
group_concat(sizes.value separator ';') as sizes
from product_sizes, sizes, products
where product_id=products.id and size_id=sizes.id
group by product_id
select products.id, products.name,
group_concat(sizes.value separator ';') as sizes
from product_sizes
inner join sizes on (size_id=sizes.id)
right join products on (product_id=products.id)
group by product_id order by id;
`Phone` varchar(15) NOT NULL
`Phone` char(15) NOT NULL
или (если не хранятся в значениях нецифровые символы - скобки, например)`Phone` int NOT NULL
mysql> select email, group_concat(concat(character_name, ':',
class_name, ' ',character_level,' lvl') separator ', ') as Chars
from characters,players,classes
where player_id=players.id and class_id=classes.id group by player_id;
+--------+--------------------------------------------+
| email | Chars |
+--------+--------------------------------------------+
| a@a.ru | Merlin:wizard 70 lvl, Conan:warrior 80 lvl |
| b@b.ru | Azariel:warrior 50 lvl, Bilbo:thief 20 lvl |
+--------+--------------------------------------------+
2 rows in set (0.00 sec)