CodeIgniter Forums

Full Version: Problem with Subqueries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, 
I can't transform my sql request into codeigniter,
if someone will help me.
Thank you

SELECT a.id_article, a.title, a.text
FROM articles a
JOIN category c ON a.id_category  = c.id_category 
WHERE a.id_article = (
    SELECT MIN(a2.id_article)
    FROM articles a2
    WHERE a2.id_category  = c.id_category 
    AND c.id_parent = 4
)
GROUP BY c.id_category 
ORDER BY a.id_article ASC
for subselect

Code:
$builder->where('a.id_article', function(BaseBuilder $builder) {
    return $builder->select('MIN(a2.id_article)', false)->from('articles a2')->where('a2.id_category  = c.id_category')->where('c.id_parent = 4');
});
(09-27-2021, 03:15 AM)ikesela Wrote: [ -> ]for subselect

Code:
$builder->where('a.id_article', function(BaseBuilder $builder) {
    return $builder->select('MIN(a2.id_article)', false)->from('articles a2')->where('a2.id_category  = c.id_category')->where('c.id_parent = 4');
});

Thank you so much