issue with database query

Im trying to get data from a DB, but I ran into an little issue, as im trying to get data from table ‘product_translation’ which has a column called ‘attribute’ which as 2 values (name & description) and a column ‘translation’ where the value is that I need, when using the query below it will return the results double.




| product_id | attribute      | translation       | language |

--------------------------------------------------------------

| 1          | name           | some name         | de       |

--------------------------------------------------------------

| 2          | description    | lorem ipsum dolor | de       |

--------------------------------------------------------------

more




         $query = (new \yii\db\Query())

         ->select(['a.id', 'a.api_id', 'a.api_name' , 'b.translation as name' , 'c.translation as description'])

         ->from(['a' => 'product'])

         ->leftJoin( ['b' => 'product_translation'] ,

                      'b.product_id = a.id AND b.attribute = "name" AND b.language = "de"')

         ->leftJoin( ['c' => 'product_translation'] ,

                     'c.product_id = a.id AND c.attribute = "description" AND b.language = "de"')

         ->all();

You can try this :




$query = (new \yii\db\Query())

         ->select(['a.id', 'a.api_id', 'a.api_name' , 'b.attribute' , 'c.translation'])

         ->from(['a' => 'product'])

         ->innerJoin( ['b' => 'product_translation'] ,

                      'b.product_id = a.id AND b.attribute = "name" AND b.language = "de"')

         ->innerJoin( ['c' => 'product_translation'] ,

                     'c.product_id = a.id AND c.attribute = "description" AND b.language = "de"')

         ->all();



im not looking for the data from the attribute column, but i need to filter that column.

attribute name -> translation = value 1

attribute description -> translation = value 2

Sorry, there is a mistake. You can use INNER JOIN instead of LEFT JOIN

Ok I did not know that, nice, and if I need to add one more I use rightJoin, but what if I need another one…?