, , !
@jmucchiello: PHP. , MySQL , SQL-.
, , , . - : descriptionView.
:
SELECT * FROM descriptionView WHERE lang_code = "en" AND product_id = 80007
, :
SELECT
descriptions.code,
IFNULL(t1.label, t2.label) AS label,
IFNULL(t1.short_description, t2.short_description) AS short_description,
IFNULL(t1.long_description, t2.long_description) AS long_description
FROM
descriptions
LEFT JOIN
translations t1
ON
t1.description_id = descriptions.id AND t1.lang_id =
(
SELECT
id
FROM
languages
WHERE
code = "fr"
)
LEFT JOIN
translations t2
ON
t2.description_id = descriptions.id AND t2.is_default = 1
WHERE
descriptions.id = 1
, "1" "fr", , , .
, - :
LEFT JOIN
translations t1
ON
t1.description_id = descriptions.id AND t1.lang_id = languages.id
FROM.
, WHERE, .
So my last request would look like this:
CREATE VIEW descriptionView AS
SELECT
languages.code as lang,
descriptions.code,
IFNULL(t1.label, t2.label) AS label,
IFNULL(t1.short_description, t2.short_description) AS short_description,
IFNULL(t1.long_description, t2.long_description) AS long_description
FROM
descriptions,
languages
LEFT JOIN
translations t1
ON
t1.description_id = descriptions.id AND t1.lang_id = languages.id
LEFT JOIN
translations t2
ON
t2.description_id = descriptions.id AND t2.is_default = 1
Then I could request this view using:
SELECT * FROM descriptionView WHERE lang_code = "en" AND product_id = 80007
source
share