join select from multiple row values?

Posted by user1869132 on Stack Overflow See other posts from Stack Overflow or by user1869132
Published on 2012-12-02T04:19:46Z Indexed on 2012/12/02 5:04 UTC
Read the original article Hit count: 186

Filed under:
|
|

Two tables

1) product

--------------------
id  |  Name   |  price
1   |   p1    |    10
2   |   p2    |    20
3   |   p3    |    30

2) product_attributes:

---------------------------------------------------
id | product_id | attribute_name | attribute_value
---------------------------------------------------
1  |   1        |  size          |     10
2  |   1        |  colour        |     red
3  |   2        |  size          |     20

I need to join these two tables. In the where clause I need to match both the two rows attribute values. Is it possible to get the result based on two rows value. Here if size=10 and colour=red.

Output should be

1   |   p1    |    10

It could be greatly helpful to get a query for this.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql