I have this query and I need it to be in the CodeIgniter way (query builder). I know how to use the standard query builder class functions, but I have difficulties to find a way how to build a LEFT JOIN
with an inner SELECT
clause using the CI Query Builder Class.
SELECT *
FROM sma_products p
LEFT JOIN (SELECT product_id,
Count(*)
FROM sma_sale_items
GROUP BY product_id) s
ON p.id = s.product_id
ORDER BY ` Count(*) ` DESC
See Question&Answers more detail:os