SELECT
`table1`.`model`,
`table1`.`quantity`,
SUM(table2.sale_quantity)
FROM `table1`
JOIN `table2` ON `table1`.`model`=`table2`.`model`
WHERE
`table1`.`manufacturer_id` = 'apple'
AND `table1`.`quantity` < 20
GROUP BY `table1`.`model`, `table1`.`quantity`;
SELECT <Список полей1>, SumFromT2
FROM table1
LEFT JOIN
( SELECT model, SUM(sale_quantity) AS SumFromT2 FROM table2 GROUP BY model) AS T2
ON table1.model = T2.model
WHERE <Уловия ограничивающие финальную выборку>
<?php
if ($reviews) {
foreach ($reviews as $review) {
if (!preg_match('/[^A-Za-z0-9]/', $review['text'])) {
echo '<div class="review-list">
<div class="author"><b>' . $review['author'] .'</b> '. $text_on . $review['date_added'] . '</div>
<div class="rating"><img src="catalog/view/theme/default/image/stars-' . $review['rating'] . '.png" alt="' . $review['reviews'] .'" /></div>
<div class="text">' . $review['text'] .'</div>
</div>';
}
}
}