Answer the question
In order to leave comments, you need to log in
How to count child elements?
There are two tables :
Firms table:
ID Name
1 Sony
2 Panasonic
3 Samsung
-------------------------------------------------- ----------
Table phones:
id Firma_ID Phone
1 1 332-55-56
2 1 332-50-01
3 2 256-39-11
4 3 556-39-11
5 3 456-39- 11
----------------------------------------------
have a request :
$phones_count = DB::table('firms')
->leftJoin('phones', 'firms.id', '=', 'phones.firma_id')
->count();
Answer the question
In order to leave comments, you need to log in
SELECT Firms.Name, Count(*)
FROM phones
LEFT JOIN Firms ON Firms.id = phones.Firma_id
GROUP BY Firms.Name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question