create view currentarticles as ((select c.id, c.descr, c.art_group_id, c.trade_name_id, c.comment, c.combi, sum(ah.netto) as netto, sum(ah.netto_customer) as netto_customer, sum(ah.netto_vip_customer) as netto_vip_customer, sum(ah.bonus) as bonus, sum(ah.points) as points, ch.vat_id
from article c, article_history ch, article_history ah, combi_article_content cc, article a
WHERE c.combi AND c.id=cc.combi_art_id AND cc.art_id= a.id AND c.id = ch.art_id AND a.id=ah.art_id
AND now()>ch.valid_from AND now()<ch.valid_to AND now()>=ah.valid_from AND now()<ah.valid_to
GROUP BY c.id, c.descr, c.art_group_id, c.trade_name_id, c.comment, c.combi, ch.vat_id)
UNION
(select id, descr, art_group_id, trade_name_id, comment, combi, netto, netto_customer, netto_vip_customer, bonus, points, vat_id
FROM article, article_history WHERE not article.combi AND id = article_history.art_id AND now()>=valid_from AND now()<valid_to));


 
