Since I am not a MySQL expert, I am having trouble determining how to ask a search engine for advice on this topic.
I have the following table:
+------------+--------------+-------------------+
| product_id | attribute_id | text |
+------------+--------------+-------------------+
| 1770 | 57 | wi-fi |
| 1770 | 58 | bluetooth |
+------------+--------------+-------------------+
There are many other products with many attributes.
I need to select product_id
that has text
= wi-fi
and text
= bluetooth
(in different rows). The table name is product_attribute
.
I have tried the following:
SELECT *
FROM product_attribute
WHERE product_attribute.text = 'wi-fi'
AND product_attribute.text = 'bluetooth';
However no results are returned since in one row we have text = wi-fi
and another row has text = bluetooth
, whereas my query is looking for both wi-fi
and bluetooth
in the same row.
How can I get product_id = 1770
by making the query select from the text
column in different rows with the same product_id
?
Here is SQL Fiddle.