I have three tables (product
, product_description
, product_store_description
).
product
This table has one row
+----------+---------------------+
|product_id| description |
+----------+---------------------+
| 1 |'regular description'|
+----------+---------------------+
product_description
This table has zero rows
+----------+-----------+--------+
|product_id|description|language|
+----------+-----------+--------+
product_store_description
This table has zero rows
+----------+-----------+--------+--------+
|product_id|description|language|store_id|
+----------+-----------+--------+--------+
I would like to return the .description
column for all tables WHERE product.product_id = '1'
.
So in this case the output I would like would be
$row = $result->fetch_assoc();
echo '<pre>';
var_dump($row);
echo '</pre>';
array (size=3)
'p_description' => string 'regular description' (length=19)
'pd_description' => string '' (length=0)
'psd_description' => string '' (length=0)
I have tried many variations of my SQL and this is how it stands at the moment.
SELECT p.description AS p_description ,pd.description AS pd_description, psd.description AS psd_description FROM product AS p
RIGHT JOIN product_description AS pd ON(pd.product_id = p.product_id)
RIGHT JOIN product_store_description AS psd ON(psd.product_id = p.product_id)
WHERE p.product_id = '1'
AND pd.language = 'en'
AND psd.language = 'en' AND psd.store_id = 1;
This returns zero rows
I have searched for an answer which has led me to use a RIGHT JOIN
but this has not solved my problem.
Ive created a SQL fiddle HERE of the example tables, unfortunately I haven't been able to get anyone answer to work yet.