Search code examples
phpmysqlcodeigniter

condition is not working please guide me how to get proper data


SELECT * 
FROM `tbl_property` 
WHERE 
    `sublocality` LIKE '%dwarka%' OR 
    `sublocality` LIKE '%delhi%' OR 
    `property_type` LIKE '%1%' OR
    `property_type` LIKE '%2%' AND
    `status` = 1 AND 
    `property_category` = 1

this is my query but where condition is not working please guide me how to get proper data with this type of sql query

enter image description here


Solution

  • Probably you need to add parentheses in your query to group OR/AND conditions:

    SELECT * 
    FROM `tbl_property` 
    WHERE 
    (
        `sublocality` LIKE '%dwarka%' OR 
        `sublocality` LIKE '%delhi%' OR 
        `property_type` LIKE '%1%' OR
        `property_type` LIKE '%2%'
    ) AND
        `status` = 1 AND 
        `property_category` = 1