SELECT menu.title, COUNT( cars.id_cars ) AS total FROM menu LEFT JOIN cars ON (cars.marka = menu.id AND menu.parent_id =96 AND menu.block =3)
GROUP BY menu.title
SELECT menu.title, COUNT(cars.id_cars) AS total FROM menu LEFT JOIN cars ON (cars.marka = menu.id AND menu.parent_id = 96 AND menu.block = 3) GROUP BY menu.title
Jardin1 wrote:i wanna get the next: BMW (4), where 4 is number of notes from table Cars.
HAVING
DECLARE @pid INT DECLARE @blo INT DECLARE @cou INT SET @pid = 96 SET @blo = 3 SET @cou = 4 --no. of BMW ;) SELECT m.title FROM menu AS m LEFT JOIN cars AS c ON c.marka = m.id WHERE m.parent_id =@pid AND m.block =@blo GROUP BY m.title HAVING COUNT(c.id_cars) = @cou
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)