表保存内容的信息 - content
:复杂MySQL的加入与替换列
+----------+-------------+-------------------+--------------------------------+
| (int) id | (int) title | (int) description | (string) tags |
+----------+-------------+-------------------+--------------------------------+
| 1 | 12 | 18 | super, awesome, must-see |
+-----------------------------------------------------------------------------+
| 4 | 25 | 26 | randomness, funny-stuff, cool |
+-----------------------------------------------------------------------------+
表中包含翻译信息 - 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.> |
+--------------------------------------------------------------+
我想实现的是,以取代content.title
translations.value
以及相同的描述(更多/更少数据为不同组件(content
)表)其中content.title
匹配translations.tid
,如:
+----------+-----------------------+---------------------------------+--------------------------------+
| (int) id | (text) title | (text) description | (string) tags |
+----------+-----------------------+---------------------------------+--------------------------------+
| 1 | Super-awesome-mustsee | <here would be the description> | super, awesome, must-see |
+-----------------------------------------------------------------------------------------------------+
到目前为止,我必须只能加入翻译数据为一个值......是的,联接所不能替代的。 :|
SELECT `content` . * , `translations`.value
FROM `content`
JOIN `translations` ON `translations`.tid = `content`.title
WHERE `translations`.code = 'en'
我该如何做到这一点?
在此先感谢!
此线路:JOIN'translations' ON'translations'.tid ='content'.title似乎是错误的:您必须加入content.id,而不是标题... – Nanocom