and-operator

Mysql query not work using and oprator


When using the following mysql query:

select * from gc_product_attribute where (attribute_id = 30 AND text like '62') and (attribute_id = 35 AND text like '71')

The values exist in the table but nothing gets return
table below

attribute_id | text
 30          |  62
 35          |  71

Solution

  • You want to return the items that have (attribute_id = 30 AND text like '62') and the items that have (attribute_id = 35 AND text like '71').

    This is different from retrieving the items that have (attribute_id = 30 AND text like '62') and have (attribute_id = 35 AND text like '71')

    It can be expressed in two ways :