L
L
lindou2019-12-22 19:35:40
SQL
lindou, 2019-12-22 19:35:40

How to make nested queries in Laravel in a database selection?

Greetings!
Wrote a request that fits the purpose.
How to translate it under Laravel for the builder?
Those. how to make a nested select with options.
Use selectRaw?
Thank you.

select (
           select count(cp.product_id)
           from product as cp
           where cp.color_id = :cid
             and cp.pr_id = :pid
             and cp.manuf_id = :mid
             and cp.comp = p.comp
       ) as total,
       p.comp,
       IF(p.comp = 1, 'Совместимый', 'Оригинальный') as name
from product p
group by p.comp;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-12-23
@lindou

->withCount(),->addSelect()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question