CodeIgniter Forums
Help writing Sql with CI4 active record - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Help writing Sql with CI4 active record (/thread-78901.html)



Help writing Sql with CI4 active record - venance - 03-25-2021

Hello. I 'm struggling to write sql with subquery, How can I write it with codeigniter methods.
Thanks!

//SQL
PHP Code:
SELECT p.idp.catIdp.imagec.id, (c.name) as category
                FROM product_feature p
                JOIN categories c ON p
.catId c.id
                WHERE p
.id IN(
                    SELECT MAX(p.idFROM product_feature p 
                    GROUP BY p
.catId 
                 




RE: Help writing Sql with CI4 active record - craig - 03-25-2021

https://codeigniter.com/user_guide/database/query_builder.html#looking-for-specific-data

Quote:$builder->where() - 5) Subqueries: You can use an anonymous function to create a subquery.



RE: Help writing Sql with CI4 active record - php_rocs - 03-25-2021

@venance,

Also, don't forget you write out the whole query using query bindings (https://codeigniter.com/user_guide/database/queries.html#query-bindings).