Welcome Guest, Not a member yet? Register   Sign In
Problem with Subqueries
#1

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
Reply
#2

You could use $db->query().
See https://codeigniter4.github.io/CodeIgnit...ar-queries
Reply
#3

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');
});
Reply
#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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB