Table that holds content information – content:
+----------+-------------+-------------------+--------------------------------+
| (int) id | (int) title | (int) description | (string) tags |
+----------+-------------+-------------------+--------------------------------+
| 1 | 12 | 18 | super, awesome, must-see |
+-----------------------------------------------------------------------------+
| 4 | 25 | 26 | randomness, funny-stuff, cool |
+-----------------------------------------------------------------------------+
Table that holds translation information – translations:
+-----------+---------------------------------+----------------+
| (int) tid | (text) value | (varchar) code |
+-----------+---------------------------------+----------------+
| 12 | Super-awesome-mustsee | en |
+--------------------------------------------------------------+
| 18 | <here would be the description> | en |
+--------------------------------------------------------------+
| <more translation data that is not necessary for this xmpl.> |
+--------------------------------------------------------------+
What I want to achieve is, to replace content.title with translations.value and same for description (more/less data for different components (content) tables) where content.title matches the translations.tid, like:
+----------+-----------------------+---------------------------------+--------------------------------+
| (int) id | (text) title | (text) description | (string) tags |
+----------+-----------------------+---------------------------------+--------------------------------+
| 1 | Super-awesome-mustsee | <here would be the description> | super, awesome, must-see |
+-----------------------------------------------------------------------------------------------------+
So far I’ve got to only join translation data for one value… And yes, join not replace. 😐
SELECT `content` . * , `translations`.value
FROM `content`
JOIN `translations` ON `translations`.tid = `content`.title
WHERE `translations`.code = 'en'
How do I achieve this?
Thanks in advance!
Not so complicated:
Basically you need to drop
*and specify exact columns and their aliases from joined tables. Second thing is that you yo have to create double join on the same table, one to get title translation, second to get description. To ‘replace’ it in result simply use the alias forvaluecolumn.