SELECT `p`.`id`, `p`.`title`, `p`.`slug`, `p`.`label`, `p`.`price`, `p`.`old_price`, `p`.`category_id`, `p`.`picture_id`, `p`.`brand_id`
FROM `products` AS `p`
LEFT JOIN `brands` AS `b` ON `b`.`id` = `p`.`brand_id`
WHERE `p`.`title` LIKE '%лампа%' OR `b`.`title` LIKE '%лампа%' OR `b`.`tags` like '%лампа%'
GROUP BY `products`.`id` order by `products`.`sales` desc, `products`.`views` desc
LIMIT 18
select `id`, `title`, `slug`, `label`, `price`, `old_price`, `category_id`, `picture_id`, `brand_id`
from `products` where
`brand_id` IN (select id from `brands` where `title` like '%лампа%' or `tags` like '%лампа%')
OR `title` like '%лампа%'
group by `products`.`id`
order by `products`.`sales` desc, `products`.`views` desc
limit 18