CREATE TABLE `orders` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`shop` INT(11) NOT NULL,
`order` INT(11) NOT NULL,
`curr` VARCHAR(3) NOT NULL DEFAULT 'rub',
`amount` DECIMAL(11,2) NOT NULL,
`result` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`shop`, `order`, `curr`)
);
SELECT
`table1`.`model`,
`table1`.`quantity`,
COALESCE(SUM(table2.sale_quantity), 0) AS sum_sale_quantity
FROM `table1`
LEFT JOIN `table2` ON `table1`.`model`=`table2`.`model`
WHERE
`table1`.`manufacturer_id` = 'apple'
AND `table1`.`quantity` < 20
GROUP BY `table1`.`model`, `table1`.`quantity`;
$filtered = array_filter($results, fn($el) => $el['id'] != 4);