I have two tables, one for English category names, and another for Spanish category names.
I am attempting to write a small interface which allows an admin to see for which English categories a translation must still be provided.
I will write it assuming that when you create a Spanish category, it inherits the ID of the English category.
To get a results set of corresponding categories, I have this query:
SELECT tbl_cms_categories_en.id as id,
tbl_cms_categories_en.name as en,
tbl_cms_categories_es.name as es
FROM tbl_cms_categories_en, tbl_cms_categories_es
WHERE tbl_cms_categories_en.id = tbl_cms_categories_es.id
This returns a nice list of entries:
This serves my purpose well, but there is one deficiency. If there is no row in the Spanish table, it does not return a derived row at all.
How could I change my query so that, if there is a row in the English table but not the Spanish one, I could return the derived row to say "No translation found".
Akin to:
ID = 8, en = "Security", es = "Translation Not Found"
Any guidance would be bigly appreciated.
Thanks dudes!
LEFT OUTER JOIN
, using JOIN
and ON
clauses, since an implicit join is always an inner join - Marcus Adams 2012-04-05 00:03
try
SELECT tbl_cms_categories_en.id as id,
en.name as en_name,
IF(es.name IS NULL, "No Translation Found", es.name) as es_name
FROM tbl_cms_categories_en AS en
LEFT JOIN tbl_cms_categories_es AS es
ON tbl_cms_categories_en.id = tbl_cms_categories_es.id
Why don't you set up a default value for all the Spanish rows to "Translation Not Found"?
Just a suggestion...