0

I cannot seem to figure out why my AND statements in the WHERE are being ignored?

MYSQL query

SELECT
    HomeStatus.Completed
FROM HomeInfo
    LEFT JOIN HomeSubdivision ON HomeSubdivision.HomeSubdivisionID = HomeInfo.SubdivisionID
    LEFT JOIN HomeSection ON HomeSection.HomeSectionID = HomeInfo.SectionID
    LEFT JOIN HomeStatus ON HomeStatus.HomeStatusID = HomeInfo.HomeStatusID
WHERE TRIM(CONCAT(IFNULL(TRIM(HomeInfo.HomeNumber), ''),  " ", IFNULL(TRIM(HomeInfo.HomeStreet), ''),  " ", IFNULL(TRIM(HomeInfo.HomeStreetType), ''),  " ", IFNULL(TRIM(HomeInfo.HomeStreetUnit), ''))) LIKE '%lake%' OR HomeSubdivision.SubdivisionName LIKE '%lake%'
    AND HomeStatus.Completed = 0
    AND HomeStatus.Reference = 0
    AND HomeStatus.Cancel = 0
GROUP BY SectionName
ORDER BY SubdivisionName, LENGTH(SectionName), SectionName ASC

Results:

Completed
1
1
1
1
0
1
0
John Lang
  • 127
  • 1
  • 10
  • Agreed, unsure how my question is a duplicate of that @Barmar – John Lang Aug 17 '17 at 20:23
  • It is, I missed the or in your first line of your where. Since I can't post an answer, put () around the two or conditions in that first line. IOW, put ( between where and TRIM, and at the end of that line. As written, if the first condition is true, the row will be included. – Sloan Thrasher Aug 17 '17 at 20:26
  • Oh you're right. With the long WHERE statement I missed the OR in it. Sorry about that – John Lang Aug 17 '17 at 20:28
  • That's why I get the big reps :) – Barmar Aug 17 '17 at 21:29

0 Answers0