-2

having trouble with HAVING clause of a column which exists

SELECT COUNT(*) AS `numrows`
FROM (`customers`)
LEFT JOIN `parent_companies` AS j2ee39a6a ON `j2ee39a6a`.`id` = `customers`.`parent_company_id`
WHERE `customers`.`is_approved` =  0
AND  `organization`  LIKE '%Pizza%'
OR  `title`  LIKE '%Pizza%'
OR  `picture`  LIKE '%Pizza%'
HAVING `customers`.`is_approved` = 0

I don't really understand as why it should have such issue - this is a query generated by Grocerycrud - automatically.. for searching a specific output..

Blakdronzer
  • 300
  • 3
  • 13

1 Answers1

0

HAVING is unnecesarry, because You do have that condition in WHERE

You May have wrong count because of brackets:

SELECT COUNT(*) AS `numrows`
FROM (`customers`)
LEFT JOIN `parent_companies` AS j2ee39a6a ON `j2ee39a6a`.`id` =     `customers`.`parent_company_id`
WHERE `customers`.`is_approved` =  0
AND  (`organization`  LIKE '%Pizza%' **start_bracket_here**
OR  `title`  LIKE '%Pizza%'
OR  `picture`  LIKE '%Pizza%') ** close bracket here**
HAVING `customers`.`is_approved` = 0;  ** HAVING UNNECESARRY**
jaczes
  • 1,366
  • 2
  • 8
  • 16